简体   繁体   中英

Parse SOAP with namespaces using php

I am trying to parse the following SOAP using PHP. I have tried every possible solution found in here but I did not manage it due to the namespaces used. Can please someone help?

<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>

I want to get the value AP in the Output.

$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'));
}

After spending hours I found out that the right way to print the output is:

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

instead of

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM