PHP库用于使用标记名称中的冒号来解析XML? [英] PHP library for parsing XML with a colons in tag names?

查看:101
本文介绍了PHP库用于使用标记名称中的冒号来解析XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用 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;

这篇关于PHP库用于使用标记名称中的冒号来解析XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆