0

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?

albert
  • 1,766
  • 1
  • 21
  • 24
  • You should use `SoapClient` to parse the `wsdl`. Example: https://stackoverflow.com/a/8989609/1529324 – Andrea Olivato Mar 18 '22 at 02:10
  • @AndreaOlivato but this is the only way ? i need only to convert the string to a true xml or any accessible object. – albert Mar 18 '22 at 02:20
  • You can use a [simplexml_load_string](https://www.php.net/manual/en/function.simplexml-load-string.php) to just get an XML object but that's not the purpose of a wsdl – Andrea Olivato Mar 18 '22 at 02:26
  • @AndreaOlivato simplexml dont work with string generated with complex xml like generated by wdsl. Always return null for me. – albert Mar 18 '22 at 04:02

1 Answers1

0

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);
Zaid Naim
  • 16
  • 2