Declare namespaces within XPath expression

后端 未结 3 1914
Happy的楠姐
Happy的楠姐 2021-01-18 18:01

My application needs to evaluate XPath expression against some XML data. Expression is provided by user at runtime. So, I cannot create XmlNamespaceManager to p

3条回答
  •  暖寄归人
    2021-01-18 18:40

    If the same prefix can be bound to different namespaces and prefixes aren't known in advance, then the only pure XPath way to specify such expressions is to use this form of referring to elements:

    someName[namespace-uri() = 'exactNamespace']
    

    So, a particular XPath expression would be:

    /*/a[namespace-uri() = 'defaultNS']/b[namespace-uri() = 'NSB']
                                             /c[namespace-uri() = 'defaultNS']
    

提交回复
热议问题