Mega Code Archive

 
Categories / Php / XML
 

Create the script that uses the DOM extension to create a list of title and book_id attributes

<?php $doc = DOMDocument::load("books.xml"); $books = $doc->getElementsByTagName("book"); foreach($books as $book) {   $titles = $book->getElementsByTagName("title");   foreach($titles as $title) {     echo $title->nodeValue . " - ";   }   $id = $book->getAttribute("book_id");     echo "book_id = $id\n"; } ?>