我得到了一个soap xml响应,我需要SessionID。我尝试使用SimpleXml_load_string,但得到了一个空对象。有没有人知道如何获得SessionID?
这是xml响应:
<?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:Header>
<Header xmlns="http://www.twinfield.com/">
<SessionID>ca363c52-c12f-4988-b06a-e0c41788e254</SessionID>
</Header>
</soap:Header>
<soap:Body>
<LogonResponse xmlns="http://www.twinfield.com/">
<LogonResult>Ok</LogonResult>
<nextAction>None</nextAction>
<cluster>https://c3.twinfield.com</cluster>
</LogonResponse>
</soap:Body>
</soap:Envelope>
答案 0 :(得分:0)
我在这里发现了一些有用的内容。阅读https://groups.google.com/forum/#!topic/soap4r/-5IwhynDoEU:
答案 1 :(得分:0)
尝试使用DOM。这是一种方式:
$s = '<?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:Header>
<Header xmlns="http://www.twinfield.com/">
<SessionID>ca363c52-c12f-4988-b06a-e0c41788e254</SessionID>
</Header>
</soap:Header>
<soap:Body>
<LogonResponse xmlns="http://www.twinfield.com/">
<LogonResult>Ok</LogonResult>
<nextAction>None</nextAction>
<cluster>https://c3.twinfield.com</cluster>
</LogonResponse>
</soap:Body>
</soap:Envelope>';
$doc = new DOMDocument();
$doc->loadXML( $s );
echo $doc->getElementsByTagName('SessionID')->item(0)->nodeValue;