Having trouble Parsing some XML

Discussion in 'PHP' started by Danny, Jan 10, 2011.

  1. #1
    Hi,

    I am trying to parse the following XML file to grab just some of the information. However am having issues because it is not a standard format or well formed document.

    The XML I am trying to parse is http://xml.afl.com.au/expandablegamebar.aspx?roundid=777

    I want to grab the Home team, away team, venue and start time out of each of the nodes so i can then import them into a databse.

    Can anyone give me any tips on how I could achieve this?

    Dan
     
    Danny, Jan 10, 2011 IP
  2. IAreOwn

    IAreOwn Active Member

    Messages:
    46
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    95
    #2
    im using SimpleXMLElement, just play around with it...
    
    <?php
    
    $xml_url = file_get_contents('http://xml.afl.com.au/expandablegamebar.aspx?roundid=777');
    $xml     = new SimpleXMLElement($xml_url);
    
    //print '<pre>';
    //print_r($xml);
    //print '</pre>';
    
    foreach($xml -> r -> m as $data)
    {
       echo "Venue:".$data -> attributes() -> ven ."<br />";
       echo "Start Time:".$data -> attributes() -> starttime ."<br />";
       echo "Away:".$data  -> away -> attributes()  -> name."<br />";
       echo "Home:".$data  -> home -> attributes()  -> name."<br />";
    }
    ?>
    
    PHP:
     
    IAreOwn, Jan 10, 2011 IP
  3. bee2bee

    bee2bee Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    <?php

    $xml = simplexml_load_file("http://xml.afl.com.au/expandablegamebar.aspx?roundid=777");


    foreach($xml->r->m as $value){
    echo $value->attributes()->ven;
    echo $value->away->attributes()->name;
    echo $value->home->attributes()->name;
    }
    ?>
     
    bee2bee, Jan 12, 2011 IP