V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
csx163
V2EX  ›  PHP

如何解析这个SOAP XML

  •  
  •   csx163 · 2012-03-18 15:35:03 +08:00 · 9335 次点击
    这是一个创建于 4423 天前的主题,其中的信息可能已经有所发展或是发生改变。
    对方返回一个这样的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>
    3 条回复    1970-01-01 08:00:00 +08:00
    yoyicue
        1
    yoyicue  
       2012-03-18 15:42:52 +08:00
    看了看部门API的实例,用的是这个:
    http://php.net/manual/en/class.soapclient.php
    yoyicue
        2
    yoyicue  
       2012-03-18 15:44:17 +08:00
    csx163
        3
    csx163  
    OP
       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);
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   906 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 22:22 · PVG 06:22 · LAX 15:22 · JFK 18:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.