简体   繁体   中英

Parse xml/wsdl string with PHP

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?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM