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
Did you try XMLReader? http://php.net/manual/en/book.xmlreader.php
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.
精彩评论