AeroProDrive Posted October 15, 2020 Share Posted October 15, 2020 Hi Guys, I have this SOAP message to be parsed using SimpleXML: <soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:body> <isokresponse xmlns="http://tempuri.org/"> <isokresult>1</isokresult> </isokresponse> </soap:body> </soap:envelope> Then I load the XML: $xml = simplexml_load_string($result); I assume I need to register namespace e.g. $xml->registerXPathNamespace("soap","http://schemas.xmlsoap.org/soap/envelope/"); But what's next? How do I get the value of the element isokresult? Thank you so much Quote Link to comment https://forums.phpfreaks.com/topic/311607-parse-soap-response/ Share on other sites More sharing options...
requinix Posted October 15, 2020 Share Posted October 15, 2020 If all you want is the isokresult then you can get it... well, I won't say "easily" because SOAP just loves using namespaces, but it is a one-liner. Kinda. Don't need XPath. (string)$xml ->children("http://schemas.xmlsoap.org/soap/envelope/") // switch to soap namespace ->body // <soap:body> ->children("http://tempuri.org/") // switch to this isokwhatever namespace ->isokresponse // <isokresponse> ->isokresult // <isokresult> (still in the isok namespace) Quote Link to comment https://forums.phpfreaks.com/topic/311607-parse-soap-response/#findComment-1581925 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.