我正在嘗試獲取faultstring元素的內(nèi)容,而且我更習(xí)慣于 SimpleXML 的對(duì)象語(yǔ)法 ( $xml->...->faultstring.) 下面的 DomDocument 方法有效,但我更愿意堅(jiān)持使用 SimpleXML。PHP 版本 5.6.40,Libxml 2.9.1。$xmlResponse = '<?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> <soap:Fault> <faultcode>soap:Client</faultcode> <faultstring>Server did not recognize the value of HTTP Header SOAPAction: https://gw1.domain.com:4430/.</faultstring> <detail /> </soap:Fault> </soap:Body> </soap:Envelope>';// DOES NOT WORK$xml = simplexml_load_string($xmlResponse,NULL,NULL,"http://schemas.xmlsoap.org/soap/envelope/");$faultstring = (string) ($xml->Body->Fault->faultstring);var_dump($faultstring);// WORKS$_DomObject = new DOMDocument;$_DomObject->loadXML($xmlResponse);if (!$_DomObject) die("Error while parsing the document");$s = simplexml_import_dom($_DomObject);foreach(['faultcode','faultstring','detail'] as $tag) { echo $tag.' => '.$_DomObject->getElementsByTagName($tag)[0]->textContent.'<br/>';}
- 1 回答
- 0 關(guān)注
- 158 瀏覽
添加回答
舉報(bào)
0/150
提交
取消