nerdexam
Zend

200-710 · Question #176

How can the id attribute of the 2nd baz element from the XML string below be retrieved from the SimpleXML object found inside $xml? ``xml <?xml version='1.0'?> <foo> <bar> <baz id='1'>One</baz> <baz…

The correct answer is E. $xml->bar->baz[1]->attributes()->id. See the full explanation below for the reasoning.

XML & Web Services

Question

How can the id attribute of the 2nd baz element from the XML string below be retrieved from the SimpleXML object found inside $xml?
<?xml version='1.0'?>
<foo>
 <bar>
 <baz id='1'>One</baz>
 <baz id='2'>Two</baz>
 </bar>
</foo>

Options

  • A$xml->getElementById('2');
  • B$xml->foo->bar->baz[2]['id']
  • C$xml->foo->bar[1]['id']
  • D$xml->bar->baz[1]['id']
  • E$xml->bar->baz[1]->attributes()->id

How the community answered

(70 responses)
  • A
    1% (1)
  • B
    3% (2)
  • C
    14% (10)
  • D
    7% (5)
  • E
    74% (52)

Topics

#SimpleXML#attributes()#array indexing#XML attributes

Community Discussion

No community discussion yet for this question.

Full 200-710 Practice