jhylands

Good way to read xml

Jan 15th, 2012
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.46 KB | None | 0 0
  1. <?php
  2. $doc = new DOMDocument();
  3. $doc->load( 'books.xml' );
  4.  
  5. $books = $doc->getElementsByTagName( "book" );
  6. foreach( $books as $book )
  7. {
  8. $authors = $book->getElementsByTagName( "author" );
  9. $author = $authors->item(0)->nodeValue;
  10.  
  11. $publishers = $book->getElementsByTagName( "publisher" );
  12. $publisher = $publishers->item(0)->nodeValue;
  13.  
  14. $titles = $book->getElementsByTagName( "title" );
  15. $title = $titles->item(0)->nodeValue;
  16.  
  17. echo "$title - $author - $publisher\n";
  18. }
  19. ?>
Advertisement
Add Comment
Please, Sign In to add comment