0

ResponseIdとMAP_IMAGE_ZOOM1000の値を取得しようとしていますが、var_dumpから空の応答を受け取ります。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org   /soap/envelope/">
<soapenv:Header xmlns:get="http://tnb.com.my/CGIS/D/getcustareasnapshotpro"  xmlns:bsm="http://www.tnb.com.my/CGIS/schemas/bsmfpro" xmlns:cgis="http://tnb.com.my/CGIS/D/cgis_cmccustomermgnt"/>
<soapenv:Body xmlns:get="http://tnb.com.my/CGIS/D/getcustareasnapshotpro" xmlns:bsm="http://www.tnb.com.my/CGIS/schemas/bsmfpro" xmlns:cgis="http://tnb.com.my/CGIS/D/cgis_cmccustomermgnt">
<get1:GetCustAreaSnapshotResponseParam xmlns:get1="http://tnb.com.my/CGIS/D/getcustareasnapshotcon">
     <ResponseHdr>
        <bsm:ResponseId>gero etgero etgero etgero etgero</bsm:ResponseId>
        <bsm:ResTransactionId>123456789012345</bsm:ResTransactionId>
        <bsm:ProviderId>CGIS</bsm:ProviderId>
        <bsm:ResTimestamp>2004-02-15T02:44:14</bsm:ResTimestamp>
        <bsm:ResStatus>SUCC</bsm:ResStatus>
        <bsm:MsgCode>IM-001</bsm:MsgCode>
        <bsm:MsgDesc>Success</bsm:MsgDesc>
     </ResponseHdr>
     <ResGetCustAreaSnapshot>
        <cmc:GetCustAreaSnapshot xmlns:cmc="http://tnb.com.my/CGIS/D/cmc_customermgnt">
        <cmc:MAP_IMAGE_ZOOM1000>abc</cmc:MAP_IMAGE_ZOOM1000>
        </cmc:GetCustAreaSnapshot>
     </ResGetCustAreaSnapshot>
  </get1:GetCustAreaSnapshotResponseParam>

$Envelope = simplexml_load_string($responseXml);

$Envelope->registerXPathNamespace('soap','http://schemas.xmlsoap.org/soap/envelope/');
$Envelope->registerXPathNamespace('bsm','http://www.tnb.com.my/CGIS/schemas/bsmfpro/');
$Envelope->registerXPathNamespace('cmc','http://tnb.com.my/CGIS/D/cgis_cmccustomermgnt/');
$Envelope->registerXPathNamespace('get','http://tnb.com.my/CGIS/D/getcustareasnapshotcon/');
$result = $Envelope->xpath('soap:Envelope/soap:Body/get:GetCustAreaSnapshotResponseParam/ResponseHdr/bsm:ResponseId');

var_dump($result);

die;

どんな助けでも大歓迎です。ありがとうございました !!

4

2 に答える 2

0

これを試して:

ns.xml として保存します。

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header xmlns:get="http://tnb.com.my/CGIS/D/getcustareasnapshotpro"  xmlns:bsm="http://www.tnb.com.my/CGIS/schemas/bsmfpro" xmlns:cgis="http://tnb.com.my/CGIS/D/cgis_cmccustomermgnt"/>
    <soapenv:Body xmlns:get="http://tnb.com.my/CGIS/D/getcustareasnapshotpro" xmlns:bsm="http://www.tnb.com.my/CGIS/schemas/bsmfpro" xmlns:cgis="http://tnb.com.my/CGIS/D/cgis_cmccustomermgnt">
        <get1:GetCustAreaSnapshotResponseParam xmlns:get1="http://tnb.com.my/CGIS/D/getcustareasnapshotcon">
            <ResponseHdr>
                <bsm:ResponseId>gero etgero etgero etgero etgero</bsm:ResponseId>
                <bsm:ResTransactionId>123456789012345</bsm:ResTransactionId>
                <bsm:ProviderId>CGIS</bsm:ProviderId>
                <bsm:ResTimestamp>2004-02-15T02:44:14</bsm:ResTimestamp>
                <bsm:ResStatus>SUCC</bsm:ResStatus>
                <bsm:MsgCode>IM-001</bsm:MsgCode>
                <bsm:MsgDesc>Success</bsm:MsgDesc>
            </ResponseHdr>
            <ResGetCustAreaSnapshot>
                <cmc:GetCustAreaSnapshot xmlns:cmc="http://tnb.com.my/CGIS/D/cmc_customermgnt">
                    <cmc:MAP_IMAGE_ZOOM1000>abc</cmc:MAP_IMAGE_ZOOM1000>
                </cmc:GetCustAreaSnapshot>
            </ResGetCustAreaSnapshot>
        </get1:GetCustAreaSnapshotResponseParam>
    </soapenv:Body>
</soapenv:Envelope>

ノードを取得する PHP コード:

<?php
$xml = simplexml_load_file( 'ns.xml' );

$xml->registerXPathNamespace('b', 'http://www.tnb.com.my/CGIS/schemas/bsmfpro');
$xml->registerXPathNamespace('c', 'http://tnb.com.my/CGIS/D/cmc_customermgnt');

$xpath = $xml->xpath( '//b:ResponseId | //c:MAP_IMAGE_ZOOM1000' );

foreach( $xpath as $key => $value ) {
    // echo the node name and its value
    echo $value->getName() . ' => ' . $value . "\n<br>";
}
?>

お役に立てれば。

于 2012-07-18T06:53:25.823 に答える
0

何らかの理由で、最後ResponseIdがうまくいきません。

しかし、私は「だまされ」、の最初の子を選択できますResponseHdr:

$result = $Envelope->xpath('//soapenv:Envelope/soapenv:Body/get1:GetCustAreaSnapshotResponseParam/ResponseHdr/*[1]');

編集:これは、 SimpleXMLで実行できた最高のものです。ただし、より良い代替手段になる可能性があるため、DOMDocument を試してみます。

$result = $Envelope->xpath('//soapenv:Envelope/soapenv:Body/get1:GetCustAreaSnapshotResponseParam/ResponseHdr');    
foreach( $result[0]->children('bsm', true) as $node) var_dump( $node->getName() . ' = ' . (string) $node);

$result = $Envelope->xpath('//soapenv:Envelope/soapenv:Body/get1:GetCustAreaSnapshotResponseParam/ResGetCustAreaSnapshot/*[1]');    
foreach( $result[0]->children('cmc', true) as $node) var_dump( $node->getName() . ' = ' . (string) $node);

上記のコードを指定すると、次の出力を取得できました。

string(45) "ResponseId = gero etgero etgero etgero etgero"
string(34) "ResTransactionId = 123456789012345"
string(17) "ProviderId = CGIS"
string(34) "ResTimestamp = 2004-02-15T02:44:14"
string(16) "ResStatus = SUCC"
string(16) "MsgCode = IM-001"
string(17) "MsgDesc = Success"
string(24) "MAP_IMAGE_ZOOM1000 = abc"
于 2012-07-18T01:53:53.113 に答える