名前空間とリクエスト名がわかれば、XML SOAP を解析できます。
さまざまな種類の SOAP リクエストがあるため、SOAP ファイルでリクエスト名を取得したいと考えています。私の SOAP の一部の抜粋:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://schema.example.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
>
<SOAP-ENV:Body>
**<ns1:SendMailling>**
<campagne xsi:type="ns1:Campaign"><ActivateDedup xsi:nil="true"/><BillingCode xsi:nil="true"/><DeliveryFax xsi:type="ns1:DeliveryFax"/>
<DeliveryMail xsi:type="ns1:DeliveryMail">
...
PHP コード:
if(is_file($file))
{
$content=file_get_contents($file);
$xml = simplexml_load_string($content);
$xml->registerXPathNamespace('ns1', 'http://schema.example.com');
foreach ($xml->xpath('\\SOAP-ENV:') as $item)
{
//certainly the bad way?
echo "<pre>";
print_r($item);
echo "</pre>";
}
echo "<pre>";
print_r($xml);
echo "</pre>";
}
結果が得られません...表示させたい: 'SendMailling' (リクエスト名を特定)
具体的に指定すると
//foreach($xml->xpath('//ns1:SendMailling') as $item)
問題はありません。
やってみ foreach($xml->xpath('//ns1') as $item)
た$xml->xpath('//SOAP-ENC'), $xml->xpath('//Body')
けど…