简体   繁体   English

PHP函数,用于将xml解析为不会剥离具有名称空间的节点的数组

[英]PHP function for parsing xml into array that doesn't strip nodes with namespaces

I am trying to parse an rss feed that is using the well formed web comment api and having some issues pulling in parts of the XML that contain namespaces. 我试图解析使用格式正确的Web注释api的rss提要,并且在提取包含名称空间的XML部分时遇到一些问题。 I checked here: 我在这里检查:

PHP parsing XML file with and without namespaces PHP解析带有和不带有名称空间的XML文件

but it seems his solution was more for just one specific namespace. 但似乎他的解决方案仅适用于一个特定的名称空间。 Here is my XML: 这是我的XML:

 <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/">
<channel>
<title>Some TITLE</title>
<link>http://www.somelink.com</link>
<description>Make it happen.</description>
<dc:language />
<generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator>
<item>
<title>Blah blah blah</title>
<link>http://www.somelink.com</link>
<pubDate>Wed, 21 Jul 2010 16:30:00 GMT</pubDate>
<guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9612038</guid>
<dc:creator>Chris Pendleton</dc:creator>
<slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">

I have tried using several objects to array functions that I typically use for parsing XML but they are leaving out all the nodes that contain namespaces. 我尝试使用多个对象来排列通常用于解析XML的函数,但它们忽略了所有包含名称空间的节点。 Suggestions? 有什么建议吗? Really all I need is to get at the object for each node. 我真正需要的只是获取每个节点的对象。

TIA TIA

You're parsing RSS, a well-established task. 您正在解析RSS,这是一项完善的任务。 Have you considered using someone else's code instead of writing your own? 您是否考虑过使用别人的代码而不是编写自己的代码 There are lots of options, a quick Google for php rss parser pulls up many good (and some bad) options... 有很多选项,针对php rss parser的快速Google会带来很多好的(有些不好的)选项...

If you insist on doing it yourself, the DOM has namespace support -- all the methods ending in "NS" work with namespaced XML elements & attributes. 如果您坚持要自己做, 则DOM具有名称空间支持-所有以“ NS”结尾的方法都可以使用名称空间XML元素和属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM