我在学习如何用PHP的简单XML解析XML。我的代码是:用PHP的simpleXML解析XML
<?php
$xmlSource = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?> <Document xmlns=\"http://www.apple.com/itms/\" artistId=\"329313804\" browsePath=\"/36/6407\" genreId=\"6507\"> <iTunes> myApp </iTunes> </Document>";
$xml = new SimpleXMLElement($xmlSource);
$results = $xml->xpath("/Document/iTunes");
foreach ($results as $result){
echo $result.PHP_EOL;
}
print_r($result);
?>
当这运行它返回一个空白屏幕,没有错误。如果我从文档标记中删除所有属性,则返回:
myApp SimpleXMLElement Object ([0] => myApp)
这是预期结果。
我在做什么错?请注意,我无法控制XML源,因为它来自Apple。
太棒了!你能指点我详细解释这个功能的文档吗? – SooDesuNe 2010-03-06 01:47:44
嗯,就是这样的事情:就我所知,没有关于如何处理默认名称空间的文档。 – 2010-03-06 16:37:19