用于解析带有标记名称中的冒号的 XML 的 PHP 库? [英] PHP library for parsing XML with a colons in tag names?
问题描述
我一直在尝试使用 SimpleXML,但它没有似乎不喜欢这样的 XML:
I've been trying to use SimpleXML, but it doesn't seem to like XML that looks like this:
<xhtml:div>sample <xhtml:em>italic</xhtml:em> text</xhtml:div>
那么哪个库会处理看起来像这样的标签(其中有一个冒号)?
So what library will handle tags that look like that (have a colon in them)?
推荐答案
假设你有一些这样的 xml.
Say you have some xml like this.
<xhtml:div>
<xhtml:em>italic</xhtml:em>
<date>2010-02-01 06:00</date>
</xhtml:div>
您可以像这样访问em":$xml->children('xhtml', true)->div->em;
You can access 'em' like this: $xml->children('xhtml', true)->div->em;
然而,如果你想要日期字段,这个:$xml->children('xhtml', true)->div->date;
行不通,因为您被困在 xhtml 命名空间中.
however, if you want the date field, this: $xml->children('xhtml', true)->div->date;
wont work, because you are stuck in the xhtml namespace.
您必须再次执行 'children' 才能返回默认命名空间:
you must execute 'children' again to get back to the default namespace:
$xml->children('xhtml', true)->div->children()->date;
这篇关于用于解析带有标记名称中的冒号的 XML 的 PHP 库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!