开发者

XPath select an attribute based on value

开发者 https://www.devze.com 2022-12-24 02:03 出处:网络
Using VB.Net, I have an XmlNode object开发者_StackOverflow社区, xNode. I need to select an attribute of this node if it has a particular value.

Using VB.Net,

I have an XmlNode object开发者_StackOverflow社区, xNode.

I need to select an attribute of this node if it has a particular value.

e.g. xNode.SelectSingleNode(".[@attr1='1']")

I would expect this statement to return the attribute "attr1", only if it has a value of "1". However, I get an error - Expression must evaluate to a node-set.

When I tried this - xNode.SelectSingleNode("@attr1[@attr1='1']") It always returns Nothing, even if the attribute has a value of 1.

I have tried a lot of different things, but no luck yet.

Please help. Thanks.


//*[@attr1='1']/@attr1

should do the trick.

0

精彩评论

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