开发者

Search XmlNode by attribute

开发者 https://www.devze.com 2023-04-10 00:40 出处:网络
I have XmlDocument. I开发者_运维技巧 don\'t know XPath, I only know that this xml document has node named \"h3\" with attribute id=\"PortalName\" and this attribute is unique for all xml document. How

I have XmlDocument. I开发者_运维技巧 don't know XPath, I only know that this xml document has node named "h3" with attribute id="PortalName" and this attribute is unique for all xml document. How to find this node? I try:

        XmlNode xnList = doc.SelectSingleNode("h3[@id='PortalName']");

but it does not work because it search only in root node. How to search in whole document? Thanks


Fortunately that's pretty easy:

XmlNode xnList = doc.SelectSingleNode("//h3[@id='PortalName']");

The "//h3" means "any h3 element in the whole document". (See the abbreviated syntax in the XPath spec for more information.)

0

精彩评论

暂无评论...
验证码 换一张
取 消