duan1930
duan1930
2010-07-29 18:10

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

已采纳

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. I checked here:

PHP parsing XML file with and without namespaces

but it seems his solution was more for just one specific namespace. Here is my 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. Suggestions? Really all I need is to get at the object for each node.

TIA

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • duanbai1370 duanbai1370 11年前
    点赞 评论 复制链接分享
  • dqm4977 dqm4977 11年前

    You're parsing RSS, a well-established task. 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...

    If you insist on doing it yourself, the DOM has namespace support -- all the methods ending in "NS" work with namespaced XML elements & attributes.

    点赞 评论 复制链接分享

相关推荐