views:

24

answers:

2

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:

http://stackoverflow.com/questions/2483887/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/"&gt;
<channel>
<title>Some TITLE</title>
<link>http://www.somelink.com&lt;/link&gt;
<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&lt;/link&gt;
<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/"&gt;

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

+1  A: 

Did you try XMLReader? http://php.net/manual/en/book.xmlreader.php

Mchl
Have not. Diving in now.
codeisforeva
A: 

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.

Charles
I have been using other people's functions. The problem is all the ones I have found online are not catered towards keeping the nodes which have namepsaces attached.
codeisforeva
That is because it's too difficult to coerce namespaced nodes into simple arrays. You should really be using the DOM class for general XML parsing, or one of the well known RSS parsers, like Charles suggested.
jmz
Ok I'll look into the DOM class as well. Thank you.
codeisforeva