There are tons of questions about PHP simpleXML and XML processing with namespaces. All the questions I looked at made a fundamental assumption: the code knows in advance which namespaces will be included in the incoming SOAP request. In my case, I saw inconsistent namespaces in SOAP requests.
In particular, I was working on implementing a web service to talk to the Quickbooks Web Connector (pdf) and some example of the requests I saw look like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dev="http://developer.intuit.com/"> <soapenv:Header/> <soapenv:Body> <dev:authenticate> <dev:strUserName>username</dev:strUserName> <dev:strPassword>password</dev:strPassword> </dev:authenticate> </soapenv:Body> </soapenv:Envelope>
... and some look like this:
<s11:Envelope xmlns:s11='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ns1='http://developer.intuit.com/'> <s11:Header/> <s11:Body> <ns1:authenticate> <ns1:strUserName>username</ns1:strUserName> <ns1:strPassword>password</ns1:strPassword> </ns1:authenticate> </s11:Body> </s11:Envelope>
... or that:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://developer.intuit.com/"> <SOAP-ENV:Header/> <SOAP-ENV:Body> <ns1:authenticate> <ns1:strUserName>username</ns1:strUserName> <ns1:strPassword>password</ns1:strPassword> </ns1:authenticate> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
I understand the use of xpath () to select elements, but it is assumed that you know what namespace to look for. Without any consistency in the namespace, itβs difficult for me to determine how to correctly and programmatically select node contents for processing.
The namespace is completely irrelevant to this application - could I just run the raw XML through a regular expression to remove whatever: from <whatever:mytag> ?
source share