Oleg Sh
Oleg Sh

Reputation: 9013

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

Upvotes: 0

Views: 125

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1502406

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.)

Upvotes: 1

Related Questions