PHP Classes

facing problem at the time of reading XML File

Recommend this page to a friend!

      ianaz Calendar  >  All threads  >  facing problem at the time of...  >  (Un) Subscribe thread alerts  
Subject:facing problem at the time of...
Summary:i'm facing problem at the time of XML file Reading using domxml
Messages:5
Author:rakesh v maheshwaram
Date:2006-11-14 14:56:15
Update:2006-11-15 14:58:56
 

  1. facing problem at the time of...   Reply   Report abuse  
Picture of rakesh v maheshwaram rakesh v maheshwaram - 2006-11-14 14:56:15
hi friend

i am rakesh maheshwaram from Surat-Gujarat. Actually i'm facing problem when reading XML File.

Actually i am using php ver 4.4.4. i want load data from the xml file for that i am using domxml. this code work fine in php ver 5 but not worked in ver 4.4

the code is like this

//books.xml
<?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>


//php file

<?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";
}
?>

the server shows error like this:
Parse error: parse error, unexpected T_OBJECT_OPERATOR in C:\Apache
Group\Apache2\htdocs\Formphp\test2.php on line 21

if i am removed all this ->items(0) from the code like $author = $authors->nodeValue; then it shows another error

Fatal error: Cannot instantiate non-existent class: domdocument in C:\Apache Group\Apache2\htdocs\Formphp\test2.php on line 14


2) i am trying to read another xml file

//mymovies.xml
<?xml version="1.0" encoding="utf-8" ?>
<movies>
<movie>
<title>Star Wars</title>
<year>1977</year>
</movie>
<movie>
<name>Apocalypse Now</name>
<year>1979</year>
</movie>
<movie>
<title>Raiders Of The Lost Ark</title>
<year>1981</year>
</movie>
</movies>

<?php
if (!$myxml=simplexml_load_file('mymovies.xml')){
echo 'Error reading the XML file';
}

foreach($myxml as $movie){
echo 'Title: ' . $movie->title . '<br />';
echo 'Year: ' . $movie->year . '<br /><hr />';
}

?>

in this examle the server shows error like this
Fatal error: Call to undefined function: simplexml_load_file() in C:\Apache Group\Apache2\htdocs\Formphp\test2.php on line 4

Ragsrds
Rakesh maheshwaram

  2. Re: facing problem at the time of...   Reply   Report abuse  
Picture of Silvio Rainoldi Silvio Rainoldi - 2006-11-14 17:21:37 - In reply to message 1 from rakesh v maheshwaram
Ehm, It's not my calendar class :)

  3. Re: facing problem at the time of...   Reply   Report abuse  
Picture of rakesh v maheshwaram rakesh v maheshwaram - 2006-11-15 05:26:31 - In reply to message 2 from Silvio Rainoldi
my dear

i am not saying it's your class. actually i want sollution for this.

regards
rakesh

  4. Re: facing problem at the time of...   Reply   Report abuse  
Picture of Silvio Rainoldi Silvio Rainoldi - 2006-11-15 07:43:00 - In reply to message 3 from rakesh v maheshwaram
Ah ok,
I'm sorry, I cann't solve this problem...


  5. Re: facing problem at the time of...   Reply   Report abuse  
Picture of rakesh v maheshwaram rakesh v maheshwaram - 2006-11-15 14:58:56 - In reply to message 4 from Silvio Rainoldi
ok thenks my dear, nice to meet u