SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: XML error

  1. #1
    SitePoint Zealot malluwood's Avatar
    Join Date
    Nov 2006
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XML error

    hi all

    This is my xml.php file
    PHP Code:
    <?php
    $xml
    =simplexml_load_file('xml.xml');
    $xml_new = new SimpleXMLElement($xml);
    echo 
    $xml_new->movie[0]->plot;
    ?>
    This is my xml.xml file

    Code:
    <?xml version='1.0' standalone='yes'?>
    <movies>
     <movie>
      <title>PHP: Behind the Parser</title>
      <characters>
       <character>
        <name>Ms. Coder</name>
        <actor>Onlivia Actora</actor>
       </character>
       <character>
        <name>Mr. Coder</name>
        <actor>El Act&#211;r</actor>
       </character>
      </characters>
      <plot>
       So, this language. It's like, a programming language. Or is it a
       scripting language? All is revealed in this thrilling horror spoof
       of a documentary.
      </plot>
      <rating type="thumbs">7</rating>
      <rating type="stars">5</rating>
     </movie>
    </movies>
    I am getting following errors while I run xml.php

    HTML Code:
    Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 3: parser error : Start tag expected, '<' not found in C:\wamp\www\xml.php on line 3
    
    Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: in C:\wamp\www\xml.php on line 3
    
    Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: ^ in C:\wamp\www\xml.php on line 3
    
    Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\wamp\www\xml.php:3 Stack trace: #0 C:\wamp\www\xml.php(3): SimpleXMLElement->__construct('? ?') #1 {main} thrown in C:\wamp\www\xml.php on line 3
    please help me

    Thanks

  2. #2
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just comment second line.

    <?php
    $xml=simplexml_load_file('xml.xml');
    //$xml_new = new SimpleXMLElement($xml);
    echo $xml->movie[0]->plot;
    ?>

  3. #3
    SitePoint Zealot malluwood's Avatar
    Join Date
    Nov 2006
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks

    so what is the difference between 'SimpleXMLElement' and 'simplexml_load_file'.

    please help me

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SimpleXMLElement loads xml content whereas the simplexml_load_file reads from the xml file. that is it what i think the difference.

    Is that correct aniltc??
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  5. #5
    SitePoint Addict aniltc's Avatar
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I too agree with you


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •