angelleye Posted June 16, 2007 Share Posted June 16, 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 from there on and it works just fine. Now consider the following XML response: http://angelleye.com/TodaysTransactions.xml That thing is has a whole bunch of xmlns additions to it. currently I'm trying to use XPath just like the example above but I haven't added the registernamepsace stuff yet so it's simply not finding anything with the XPath queries. Do I have to add the registernamespace method for every single one of those? And if so, how do I know what prefix to use when parsing the XML? It works just fine without doing anything with namepsaces if I just use $DOM -> getElementByTagName() but there are lots of times when I need to be able to use XPath...or even just prefer it. I've tried looking into PHP SOAP (www.php.net/soap) but that and anything else I see seems to be more about creating your own web services than simply parsing the data out of the response. Any information on this would be greatly appreciated. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/55795-trouble-with-xml-namespaces-in-web-service-responses-using-dom/ 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.