Getting elements with default namespace (no namespace prefix) using XPath

后端 未结 1 1491
北荒
北荒 2020-12-03 14:19

In this SOAP XML file, how can I get the 7 on a using a XPath query?



        
相关标签:
1条回答
  • 2020-12-03 14:36

    If you have a namespace prefix set, you could use it, like:

    //soap:Body
    

    But since the nodes you are trying to get use a default namespace, without a prefix, using plain XPath, you can only acesss them by the local-name() and namespace-uri() attributes. Examples:

    //*[local-name()="HelloWorldResult"]/text()
    

    Or:

    //*[local-name()="HelloWorldResult" and namespace-uri()='http://tempuri.org/']/text()
    

    Or:

    //*[local-name()="HelloWorldResponse" and namespace-uri()='http://tempuri.org/']/*[local-name()="HelloWorldResult"]/text()
    

    To your xml, they will all give the same result, the text 7.

    0 讨论(0)
提交回复
热议问题