National_Instruments
200-500 · Question #183
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…
The correct answer is E. $xml->bar->baz[1]['id']. See the full explanation below for the reasoning.
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->baz[2]['id']
- D$xml->foo->bar->baz[1]['id']
- E$xml->bar->baz[1]['id']
How the community answered
(44 responses)- A2% (1)
- B2% (1)
- C7% (3)
- D14% (6)
- E75% (33)
Community Discussion
No community discussion yet for this question.