angelleye Posted July 5, 2007 Share Posted July 5, 2007 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! Quote Link to comment Share on other sites More sharing options...
angelleye Posted July 6, 2007 Author Share Posted July 6, 2007 I did have to register multiple namespaces and then I just use each one where necessary in the query. for instance $XPath -> query("//ns1:TransactionDetails/ns2:PayerInfo/ns2:PayerName/text()"); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.