Hi,
I am search script for reading xml file and i found it but it not working well.
Its a simple example xml file
<?xml version="1.0" encoding="iso-8859-1"?>
<books>
<book>
<author>Jack Herrington</author>
<title>PHP Hacks</title>
<publisher>O'Reilly</publisher>
</book>
<book>
<author>Jack Herrington</author>
<title>Podcasting Hacks</title>
<publisher>O'Reilly</publisher>
</book>
</books>
and the php code i found is
<?php
$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";
}
?>
but it give error to me
Parse error: parse error, unexpected T_OBJECT_OPERATOR in c:\inetpub\wwwroot\os3\xml\read_xml.php on line 9
and line 9 is
$author = $authors->item(0)->nodeValue;
please guid me thanks