繁体   English   中英

使用 PHP 解析 xml/wsdl 字符串

[英]Parse xml/wsdl string with PHP

我使用了 php-curl,这是一个带有 soap-wsdl 的网络服务 API,它不返回 xml object 而是一个字符串,如:

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"...

如何将此字符串的内容转换为 xml 并将其解析为数组 object、json... 不是字符串?

尝试这个

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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