如何解析这个SOAP XML

2012-03-18 15:35:03 +08:00
 csx163
对方返回一个这样的XML,请教如何转换为数组.我试过了SimpleXML但是它不认<soap:Envelope ... 这个命名空间.

<?xml version="1.0" encoding="utf-8"?>
<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>
<wfjlResponse xmlns="http://test">
<wfjlResult>
<NewDataSet>
<finally>
<中文1>测试1</中文1>
<中文2>测试2</中文2>
<中文3>测试3</中文3>
</finally>
</NewDataSet>
</wfjlResult>
</wfjlResponse>
</soap:Body>
</soap:Envelope>
9344 次点击
所在节点    PHP
3 条回复
yoyicue
2012-03-18 15:42:52 +08:00
看了看部门API的实例,用的是这个:
http://php.net/manual/en/class.soapclient.php
yoyicue
2012-03-18 15:44:17 +08:00
csx163
2012-03-18 16:05:38 +08:00
@yoyicue 谢谢您的回复,我现在是用curl_setopt() POST下面这段xml获得上面的那段XML. soapclient这个类我试了很久都没有成功将下面这段XML POST到服务器,我现在的意思是反正已经获得了上面那段XML,如何将它转换为数组.

$xml_data ='<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"><v:Header /><v:Body><jkjl xmlns="http://test" id="o0" c:root="1"><hphm i:type="d:string">'. $a .'</hphm><hpzl i:type="d:string">02</hpzl><fdjh i:type="d:string">'. $b .'</fdjh><an i:type="d:string">android_client</an></jkjl></v:Body></v:Envelope>';
$url = "http://8.8.8.8/test.asmx";
$header[] = "Content-type: text/xml";//定义content-type为xml
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);
$response = curl_exec($ch);
print_r ($response);

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/29964

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX