Error getting data from XML with SimpleXML.

Discussion in 'PHP' started by Miquexia, Jun 10, 2010.

  1. #1
    Hello,

    I am trying to pull data from an XML file (The file is called online.php tho - does that matter?) with SimpleXML but i keep getting the following error:

    Personally, I think this has something do to with the first line (ofcourse):

    It has no <?XML tag. Since it just starts with the status tag.

    Am I right?

    How will I be able to fetch the data so I can use it in PHP? Kind of desperate here.

    Thanks.
     
    Miquexia, Jun 10, 2010 IP
  2. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #2
    
    $filecontent = file_get_contents('http://youfile.com/online.php');
    preg_match_all('|<status generated="(.*)">|',$filecontent,$all);
    
    PHP:
    The matches will be in $all which is an array. So do a print_r($all) and you can see exactly where the data is stored that you need.
     
    stephan2307, Jun 10, 2010 IP
  3. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #3
    simplexml can load strings/files where the first line is not an xml tag; the error you are getting is usually due to 'special' characters in the tag it is throwing an error on, or of course there is no closing tag / incorrect markup.

    How big is the xml file? Paste it if its not too big.
     
    lukeg32, Jun 10, 2010 IP