Hi Guys
I'm having a bit of bother with getting at a name space node. In fact, I've now wasted the better part of a day trying to get at it...
I have an XML file that I'm pulling down and I can access most of the nodes fine, even the name space nodes are ok. My problem is that I can't access a "child" namespace node. I think I'm pretty close and I'm just missing out on the semantics. But then again, I have been massively wrong before
Here is a bit of the XML:
and here is a bit of the boiled down parser:
Basically, I am trying to get the value from the ls:city node but this is my first real stab at namespaces and I don't really know how to get in at the child node of ls:location.
Any help would be massively appreciated.
I'm having a bit of bother with getting at a name space node. In fact, I've now wasted the better part of a day trying to get at it...
I have an XML file that I'm pulling down and I can access most of the nodes fine, even the name space nodes are ok. My problem is that I can't access a "child" namespace node. I think I'm pretty close and I'm just missing out on the semantics. But then again, I have been massively wrong before

Here is a bit of the XML:
Code:
<?xml version="1.0" encoding="UTF-8"?> <feed xmlns:ls="http://yourcompany.com/ns/1.0" xml:lang="en-US" xmlns:georss="http://www.georss.org/georss" xmlns="http://www.w3.org/2005/Atom"> <id>tag:livingsocial.com,2005:/cities</id> <link type="text/html" href="http://yourcompany.com" rel="alternate"/> <title>The Title</title> <updated>2011-08-25T08:28:55Z</updated> <entry> <id>The ID</id> <title>The Title</title> <content type="html">The HTML Content</content> <ls:merchant>The Merchant Name</ls:merchant> <ls:location> <ls:address1>Adress</ls:address1> <ls:city>The City</ls:city> <ls:state>The State</ls:state> <ls:zip>The Zip Code</ls:zip> <ls:country>The Country</ls:country> <ls:phone>The Phone Number</ls:phone> <georss:point>-28.0067947 153.4065773</georss:point> <georss:featureTypeTag>location</georss:featureTypeTag> <ls:latitude>lat</ls:latitude> <ls:longitude>lat</ls:longitude> </ls:location> <author> <name>Author Name</name> </author> </entry>
Code:
// load the file on the DOM $dom = new DomDocument(); $dom->load('http://yourcompany.com/xml'); $itemList = array(); // get the list of Items. $itemElemList = $dom->getElementsByTagName('entry'); for($i=0;$i<$itemElemList->length;$i++) { $itemList[$i] = array ( 'title' => $itemElemList->item($i)->getElementsByTagName('title')->item(0)->nodeValue, 'link' => $itemElemList->item($i)->getElementsByTagName('link')->item(0)->nodeValue, 'description' => $itemElemList->item($i)->getElementsByTagName('description')->item(0)->nodeValue, 'city' => $itemElemList->item($i)->getElementsByTagNameNS('http://yourcompany.com/ns/1.0', 'city')->item(0)->nodeValue ); }
Any help would be massively appreciated.
Comment