我需要解析soapserver的响应:
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">
<SOAP-ENV:Header>
<wsa:MessageID SOAP-ENV:mustUnderstand="0">uuid:5f7271f0-de19-11e1-8035-e656d1754971</wsa:MessageID>
<wsa:To SOAP-ENV:mustUnderstand="0">http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:wssigatewayResponse xmlns:ns1="urn:it-progress-operate:ws_operate">
<ns1:result xsi:nil="true"/>
<ttOut xmlns="urn:it-progress-operate:ws_operate">
<ttOutRow xmlns="urn:it-progress-operate:ws_operate">
<ParPos xmlns="urn:it-progress-operate:ws_operate">0</ParPos>
<ParNam xmlns="urn:it-progress-operate:ws_operate">ContentType</ParNam>
<ParVal xmlns="urn:it-progress-operate:ws_operate">text/xml</ParVal>
</ttOutRow>
<ttOutRow xmlns="urn:it-progress-operate:ws_operate">
<ParPos xmlns="urn:it-progress-operate:ws_operate">1</ParPos>
<ParNam xmlns="urn:it-progress-operate:ws_operate">Result</ParNam>
<ParVal xmlns="urn:it-progress-operate:ws_operate">200</ParVal>
</ttOutRow>
<ttOutRow xmlns="urn:it-progress-operate:ws_operate">
<ParPos xmlns="urn:it-progress-operate:ws_operate">2</ParPos>
<ParNam xmlns="urn:it-progress-operate:ws_operate">XMLDocumentOut</ParNam>
<ParVal xmlns="urn:it-progress-operate:ws_operate"><?xml version="1.0" encoding="utf-8" ?>
<DtsAgencyLoginResponse xmlns="DTS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="DTS file:///R:/xsd/DtsAgencyLoginMessage_01.xsd"><SessionInfo><SessionID>178918</SessionID><Profile>A</Profile><Language>ENG</Language><Version>1</Version></SessionInfo><AdvisoryInfo/></DtsAgencyLoginResponse></ParVal>
</ttOutRow>
</ttOut>
<ns1:opcErrorMessage/>
</ns1:wssigatewayResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
如何在最后一个ttOutRow中从ParVal获取SessionID?
答案 0 :(得分:2)
将SOAP响应加载到DOMDocument
对象中:
$soapDoc = new DOMDocument();
$soapDoc->loadXML($soapResponse);
为该文档准备一个DOMXPath
对象:
$xpath = new DOMXPath($soapDoc);
为urn:it-progress-operate:ws_operate
命名空间注册前缀:
$xpath->registerNamespace('operate', 'urn:it-progress-operate:ws_operate');
检索有效负载节点:
$path = "//operate:ttOutRow[operate:ParNam='XMLDocumentOut']/operate:ParVal";
$result = $xpath->query($path);
保存有效负载XML:
$payloadXML = $result->item(0)->nodeValue;
现在您已拥有有效负载XML字符串,请再次执行该过程:
DTS
命名空间最好将整个过程包装成一个函数,以便重新使用它。