Using Xpath With Default Namespace in C#

前端 未结 13 1487
别那么骄傲
别那么骄傲 2020-11-22 03:02

I\'ve got an XML document with a default namespace. I\'m using a XPathNavigator to select a set of nodes using Xpath as follows:

XmlElement myXML = ...;           


        
13条回答
  •  盖世英雄少女心
    2020-11-22 03:50

    You can use XPath statement without using XmlNamespaceManager like this:

    ...
    navigator.Select("//*[ local-name() = 'innerelement' and namespace-uri() = '' ]")
    ...
    

    That is a simple way of selecting element within XML with default namespace definied.

    The point is to use:

    namespace-uri() = ''
    

    which will found element with default namespace without using prefixes.

提交回复
热议问题