1

I consumed using php-curl, a webservice API with soap-wsdl which doesn't return an xml object but a string like:

string(3854) "<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/ 01/oasis- 200401-wss-wssecurity-utility-1.0.xsd"><s:Header><o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/ wss/2004/ 01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><u:Timestamp u:Id="_0"><u:Created>2022-03-18T01:53:32.688Z</ u:Created> <u:Expires>2022-03-18T01:58:32.688Z</u:Expires></u:Timestamp></o:Security></s:Header><s:Body><UrbanList xmlns="http://tempuri.org/"><D"...

How to turn the content of this string into an xml and parse this to an array, object, json... anything but a string?

4
  • 1
    You should use SoapClient to parse the wsdl. Example: stackoverflow.com/a/8989609/1529324 Commented Mar 18, 2022 at 2:10
  • @AndreaOlivato but this is the only way ? i need only to convert the string to a true xml or any accessible object. Commented Mar 18, 2022 at 2:20
  • 1
    You can use a simplexml_load_string to just get an XML object but that's not the purpose of a wsdl Commented Mar 18, 2022 at 2:26
  • @AndreaOlivato simplexml dont work with string generated with complex xml like generated by wdsl. Always return null for me. Commented Mar 18, 2022 at 4:02

1 Answer 1

1

Try this

$your_soap_string = 'YOUR SOAP STRING HERE';
$namespaces = ['s:', 'o:', 'u:']; // you need to add all if there are more
$clean_xml = str_ireplace($namespaces, '', $your_soap_string);
$xml = simplexml_load_string($clean_xml);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.