National_Instruments
200-500 · Question #137
Consider the following XML code: <?xml version="1.0" encoding="utf-8"?> <books> <book id="1">PHP 5 Power Programming</book> <book id="2">Learning PHP 5</book> </books> Which of the following…
The correct answer is C. echo $xml->book[1]; E. $c = $xml->children(); echo $c[1]. See the full explanation below for the reasoning.
Question
Consider the following XML code:
<?xml version="1.0" encoding="utf-8"?> <books> <book id="1">PHP 5 Power Programming</book> <book id="2">Learning PHP 5</book> </books> Which of the following SimpleXML calls print the name of the second book? (Choose 2) (Let $xml=simplexml_load_file("books.xml");)Options
- Aecho $xml->books->book[2];
- Becho $xml->books->book[1];
- Cecho $xml->book[1];
- Decho $xml->xpath("/books/book[@id=2]");
- E$c = $xml->children(); echo $c[1];
How the community answered
(22 responses)- A5% (1)
- B9% (2)
- C73% (16)
- D14% (3)
Community Discussion
No community discussion yet for this question.