问题描述
我正在尝试使用 simplexml 来读取 feedburner xml.我可以读取 xml 中的每个属性,但不能读取其中带有 ':' 的键.示例feedburner:origLink".当我对项目进行 vardump 时,那些带有 : 的键不会出现.我不能像 $s->item->feedburner:origLink.
I'm trying trying to use simplexml to read a feedburner xml. I can read every properties in the xml but not the keys with ':' in it. Example "feedburner:origLink". When I vardump the items, those keys with : doesn't show up. And I can't do like $s->item->feedburner:origLink.
推荐答案
您正在处理命名空间和 这篇 Sitepoint 文章 看起来是一个很好的长篇解释.或者对于更简洁的版本,请查看 PHP SimpleXML此处代码> 文档.
You're dealing with namespaces, and this Sitepoint article looks like a good long explanation. Or for a more concise version, look 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)
这篇关于simplexml 并访问 feedburner 的:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!