Using xpath on a PHP SimpleXML object, SOAP + namespaces (not working..)

后端 未结 2 939
我寻月下人不归
我寻月下人不归 2020-12-06 15:47

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)

2条回答
  •  死守一世寂寞
    2020-12-06 16:32

    You need to register the default namespace used by element as well. Because is in the default namespace it does not have any prefix but in order to your XPath to work, you need to bind also this namespace to some prefix and then use that prefix in your XPath expression.

    $response->registerXPathNamespace("ns",
        "http://webservices.site.com/definitions");
    $_res = $response->xpath('//soap:Header/ns:SessionId');
    

    XPath (1.0) expressions without a namespace prefix always match only to targets in no-namespace.

提交回复
热议问题