0

I need to parse the following XML file below:

https://www.performanceexchange.com/publisher/report/api/17adeb41da1343209a32e6790ee1a286/xml/report/stats?startDate=2012-07-01&endDate=2012-08-13

$xml = simplexml_load_file( urlencode($mediatrust_url) );

Which outputs:

SimpleXMLElement Object
(
    [@attributes] => Array
    (
        [name] => StatsReport
    )

)

So it seems that it just picks up the name of the first tag.

1 Answers1

3

Try this:

foreach($xml->attributes() as $k => $v)
{
    if($k == "name")
    {
        //do something
    }
}

Also, try using loading the XML string like this:

$sxml = simplexml_load_string(@file_get_contents($url));
mmcachran
  • 474
  • 2
  • 8
  • ok got rid of the urlencode, the XML url is https://www.performanceexchange.com/publisher/report/api/17adeb41da1343209a32e6790ee1a286/xml/report/stats?startDate=2012-07-01&endDate=2012-08-13 – user1598724 Aug 14 '12 at 17:52
  • You need to fetch the namespaces first. This should help: http://stackoverflow.com/questions/5801089/php-script-cant-read-xml-data-with-colon – mmcachran Aug 14 '12 at 20:28