PHP库用于使用标记名称中的冒号来解析XML?

编程入门 行业动态 更新时间:2024-10-24 01:56:02
本文介绍了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?

本文发布于:2023-11-12 12:40:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581517.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:冒号   标记   名称   PHP   XML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!