开发者

Search XmlNode by attribute

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜