Loading ...
Sorry, an error occurred while loading the content.

facing problem at the time of reading XML file from PHP

Expand Messages
  • gonzal_rocky
    hello friends i am facing problem at the time of reading XML file from PHP. i am using php ver 4.4.4. i want load data from the xml file for that i am using
    Message 1 of 3 , Nov 14, 2006
    • 0 Attachment
      hello friends

      i am facing problem at the time of reading XML file from PHP.
      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

      Regards
      Rocky
    • Ved Prakash
      Upgrade to php5. php5 latest build has got better support for classes than earlier releases. Regards Ved
      Message 2 of 3 , Nov 14, 2006
      • 0 Attachment
        Upgrade to php5. php5 latest build has got better support for classes
        than earlier releases.

        Regards

        Ved

        --- In bang-phpug@yahoogroups.com, "gonzal_rocky" <gonzal_rocky@...>
        wrote:
        >
        > hello friends
        >
        > i am facing problem at the time of reading XML file from PHP.
        > 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
        >
        > Regards
        > Rocky
        >
      • Ved Prakash
        Rocky, Your problem is PHP4. I would recommend you to upgrade to PHP5. But, there are ways to get over it, if you try using pear. Regards, Ved
        Message 3 of 3 , Nov 14, 2006
        • 0 Attachment
          Rocky, Your problem is PHP4. I would recommend you to upgrade to PHP5.
          But, there are ways to get over it, if you try using pear.

          Regards,

          Ved

          --- In bang-phpug@yahoogroups.com, "gonzal_rocky" <gonzal_rocky@...>
          wrote:
          >
          > hello friends
          >
          > i am facing problem at the time of reading XML file from PHP.
          > 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
          >
          > Regards
          > Rocky
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.