0

我需要解析以下 XML 文件:

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) );

哪个输出:

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

)

所以它似乎只是选择了第一个标签的名称。

4

1 回答 1

3

尝试这个:

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

此外,尝试使用加载 XML 字符串,如下所示:

$sxml = simplexml_load_string(@file_get_contents($url));
于 2012-08-14T17:41:52.550 回答