使用 php 解析具有命名空间的 SOAP


Parse SOAP with namespaces using php

我正在尝试使用PHP解析以下SOAP。我已经尝试了这里找到的所有可能的解决方案,但由于使用的命名空间,我没有管理它。可以请人帮忙吗?

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:geo="http://path.to.geo" xmlns:geo1="http://path/">
<soapenv:Header/>
<soapenv:Body>
  <geo:SendClient>
     <geo1:SendClientRequest>
        <geo1:GeneralInfo>
            <geo1:Team>AP</geo1:Team>
        </geo1:GeneralInfo>
     </geo1:SendClientRequest>
  </geo:SendClient>
</soapenv:Body>
</soapenv:Envelope>

我想在输出中获取值 AP。

$xmlData = simplexml_load_file('request.xml');
$xmlData->registerXPathNamespace('geo1', 'http://path/');
foreach ($xmlData->xpath('//geo1:GeneralInfo') as $item)
{
  print_r($item);
var_export($item->xpath('//geo1:Team'));
}

花了几个小时后,我发现打印输出的正确方法是:

$result = $item->xpath('//geo1:Team');
echo (string)$result[0];

而不是

var_export($item->xpath('//geo1:Team'));