Declare namespaces within XPath expression

后端 未结 3 1939
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:58

    Is there any possibility to specify namespaces declaration within xpath expression?

    The answer is no - it's always done in the calling environment (which is actually more flexible).

    An alternative would be to use XQuery, which does allow declaring namespaces in the query prolog.

    UPDATE (2020)

    In XPath 3.1 you can use the syntax /*/Q{http://my-namespace}a.

    Sadly, though, if you're still using Microsoft software, then the situation hasn't changed since 2011 - you're still stuck with XPath 1.0 with all its shortcomings.

提交回复
热议问题