Bir PHP SimpleXML nesne, SOAP + ad XPath kullanarak (çalışmıyor ..)

0 Cevap php

After researching this on SO and google for hours now... I hope to get some help here: (I am just one step away from running a regex to remove the namespaces completely)

Öncelikle bu XML:

<?xml version="1.0" encoding="utf-16"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header xmlns="http://webservices.site.com/definitions">
    <SessionId>0119A|1</SessionId>
  </soap:Header>
  <soap:Body>
    <Security_AuthenticateReply xmlns="http://xml.site.com/QQ">
      <processStatus>
        <statusCode>P</statusCode>
      </processStatus>
    </Security_AuthenticateReply>
  </soap:Body>
</soap:Envelope>

Şimdi bu PHP benim kod gibi görünüyor:

$response = simplexml_load_string( $str ,NULL, 
false, "http://schemas.xmlsoap.org/soap/envelope/" );
// just making sure the name space is "registered"
// but I tested all examples also with this removed
$response->registerXPathNamespace("soap",
    "http://schemas.xmlsoap.org/soap/envelope/");
$_res = $response->xpath('//soap:Header');
print_r($_res);
/*** result: simple query for the root "soap" namespace, this looks good! (so far..)
Array
(
    [0] => SimpleXMLElement Object
        (
            [SessionId] => 0119A|1
        )

)
***/

// now we query for the "SessionId" element in the XML
$_res = $response->xpath('//soap:Header/SessionId');
print_r($_res);
/*** result: this does not return anything!
Array
(
)
***/

// another approach
$_res = $response->xpath('//soap:Header/SessionId/text()');
print_r($_res);
/*** result: this does not return anything at all!
***/

// Finally, without using XPath this does work
$_res = $response->xpath('//soap:Header');
$_res = (string)$_res[0]->SessionId;
echo $_res;
/*** result: this worked
0119A|1
***/

Nasıl soap ileti XPATH ile çalışan alabilirim??

Thanks, Roman

0 Cevap