我正在尝试使用 simplexml 来读取 feedburner xml。我可以读取 xml 中的每个属性,但不能读取其中带有“:”的键。示例“feedburner:origLink”。当我对项目进行 vardump 时,那些带 : 的键不会显示。我不能像 $s->item->feedburner:origLink 那样做。
最佳答案
您正在处理命名空间,并且 this Sitepoint article看起来是一个很好的长解释。或者想要更简洁的版本,请查看 here in the PHP SimpleXML
docs .
来自文档:
<?php
$xml = '<example xmlns:foo="my.foo.urn">
<foo:a>Apple</foo:a>
<foo:b>Banana</foo:b>
<c>Cherry</c>
</example>';
$sxe = new SimpleXMLElement($xml);
$kids = $sxe->children('foo');
var_dump(count($kids));
$kids = $sxe->children('foo', TRUE);
var_dump(count($kids));
$kids = $sxe->children('my.foo.urn');
var_dump(count($kids));
$kids = $sxe->children('my.foo.urn', TRUE);
var_dump(count($kids));
$kids = $sxe->children();
var_dump(count($kids));
?>
输出:
int(0)
int(2)
int(2)
int(0)
int(1)
关于php - simplexml 并访问 feedburner 的 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3537655/