Jump to content

[SOLVED] I've loaded an XML into DOM with lots of namespaces and I'm confused...


angelleye

Recommended Posts

I'm getting a little lost with namespaces in my XML responses from API's.  I'm using DOM (DOMXPath) to parse the data out of it and before that works I have to either register the namespace in DOMXPath or strip the XML response of all the namespace information prior to loading it into DOM.  I'd rather do it the correct way and use namespaces.

 

Here's the thing.  Consider the following XML: http://www.angelleye.com/phpTraining/XML_Parsing_Samples/fmresult.xml

 

That has the xmlns="http://www.filemaker.com/xml/fmresultset" associated with it.  As such, when I load this into DOM I have the following:

 

$xmlDom = new DOMDocument();
$xmlDom -> loadXML($xmlResponse);
$xmlDomXPath = new DOMXPath($xmlDom);
$xmlDomXPath -> registerNamespace("fm", "http://www.filemaker.com/xml/fmresultset");
$records = $xmlDomXPath -> query("/fm:fmresultset/fm:resultset/fm:record");
$recordCount = $records -> length;
//etc.

 

That works great.  I just add fm: to the front of all the XPath elements as shown from there on and it works just fine.

 

Now consider the following XML: http://www.angelleye.com/angelleyephp/eBayApps/1DD3523773371373B.xml

 

That is full of namespaces and I can't seem to figure out what I need to do in order to be able to parse using XPath in the same manner.  Do I need to register ALL of those namespaces?  How do I know which namespace to use to grab which element values..??

 

Any information on this would be greatly appreciated.  I've looked into PHP SOAP (since this particular XML is indeed a SOAP response) but everything I see converts it to a PHP array and I'd rather just work with XPath.

 

Thanks!

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.