Hi,
I am trying to simple php program to read the following xml and with loop foreach wants the book title (judul) to be printed on the screen.
books.xml
<?xml version="1.0" encoding="utf-8"?>
<perpustakaan>
<buku isbn="01232312312">
<judul>PHP Programming</judul>
<pengarang>Whoever he is</pengarang>
<penerbit>KomTek Publishing</penerbit>
</buku>
<buku isbn="01534534">
<judul>Simple Programming</judul>
<pengarang>No one know</pengarang>
<penerbit>KomTek Publishing</penerbit>
</buku>
</perpustakaan>
exercise3_1.php
<?php
// Reading books XML with the DOM
$doc = new DOMDocument();
$doc->load( 'books.xml' );
$books = $doc->getElementsByTagName( "book" );
foreach( $books as $book )
{
$authors = $book->getElementsByTagName( "author" );
$author = $authors->item(0)->nodeValue;
$publishers = $book->getElementsByTagName( "publisher" );
$publisher = $publishers->item(0)->nodeValue;
$titles = $book->getElementsByTagName( "title" );
$title = $titles->item(0)->nodeValue;
echo "$title - $author - $publisher\n";
}
?>
The above code does not show me anything on screen. How to do so ?