I have XML in the following form that I want to parse with PHP (I can't change the format of the XML). Neither SimpleXML nor DOM seem to handle the different namespaces - can anyone give me sample code? The code below gives no results.
<atom:feed>
<atom:entry>
<atom:id />
<otherns:othervalue />
</atom:entry>
<atom:entry>
<atom:id />
<otherns:othervalue />
</atom:entry>
</atom:feed>
$doc = new DOMDocument();
$doc->load($url);
$entries = $doc->getElementsByTagName("atom:entry");
foreach($entries as $entry) {
$id = $entry->getElementsByTagName("atom:id");
echo $id;
$othervalue = $entry->getElementsByTagName("otherns:othervalue");
echo $othervalue;
}
SimpleXMLElement->children, orDOMElement::getElementsByTagNameNS ( string $namespaceURI , string $localName )(which would be the uri defined byatom, andentrywithout theatom:prefix), and please, just for the hell of it, find one of the hundreds of similar questions here on SO. This is NOT a new question by a long shot.$doc->getElementsByTagName("entry");The keyword in the manual is local name.