使用PHP解析soap响应

使用PHP解析soap响应,php,xml,parsing,soap,simplexml,Php,Xml,Parsing,Soap,Simplexml,我试图从下面的soap响应中获取所有元素和值作为数组。但我只得到元素,没有值 我使用这个解析器来获取元素和值。提前谢谢 这是我正在使用的代码 $response = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header/> <soapenv:Body> <toy:SearchReq xmlns:

我试图从下面的soap响应中获取所有元素和值作为数组。但我只得到元素,没有值

我使用这个解析器来获取元素和值。提前谢谢

这是我正在使用的代码

  $response = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
      <toy:SearchReq xmlns:toy="www.something.com/toy" xmlns:gen="www.something.com/gen">
         <gen: manufacturedIn="SomePlace"/>
         <toy:SearchToy>
            <toy:SearchType>
               <gen:Shop Code="WALMART"/>
            </toy:SearchType>    
         </toy:SearchToy>
         <toy:SearchToy>
            <toy:SearchType>
               <gen:Shop Code="AMAZON"/>
            </toy:SearchType>    
         </toy:SearchToy>
      </toy:SearchReq>
   </soapenv:Body>
</soapenv:Envelope>';

$doc = simplexml_load_string($response);

$path = array($doc
    ->children('http://schemas.xmlsoap.org/soap/envelope/')
    ->Body
    ->children('www.something.com/toy'));


foreach($path as $elem){
    print_r($elem);
    $elemChild = $elem->children('www.something.com/gen');
    var_dump($elemChild);
}
$response=
';
$doc=simplexml\u load\u字符串($response);
$path=数组($doc)
->儿童('http://schemas.xmlsoap.org/soap/envelope/')
->身体
->儿童(www.something.com/toy);
foreach($elem路径){
打印(elem);
$elemChild=$elem->children('www.something.com/gen');
var_dump($elemChild);
}

您可以通过注册名称空间来读取SOAP消息-如果您关心消息的SOAP部分,则只需要名称空间位

$xml = simplexml_load_string($xml);
$xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
foreach ($xml->xpath('//toy') as $toy)
{
    print_r($toy);
}

请参见此处的完整参考:

$sxe=新的simplexmlement($response)//在$response变量中,它是一个XML文件或响应
$sxe->registerXPathNamespace('d','urn:schemas-microsoft-com:xml-diffgram-v1');
$result=$sxe->xpath(//NewDataSet”);
回声“;
foreach($result[0]作为$title){
印刷品(标题);
}

有关更多信息,请访问网站:

解决方案不起作用。我已经试过了。另外,我需要一次搜索中的所有子节点。可能是针对具有已知名称空间的未知响应元素。提前感谢。
$sxe = new SimpleXMLElement($response); //in $response variable it's an XML file or response
$sxe->registerXPathNamespace('d', 'urn:schemas-microsoft-com:xml-diffgram-v1');
$result = $sxe->xpath("//NewDataSet");

echo "<pre>";
foreach ($result[0] as $title) {
    print_r($title);
}