开发者

Detecting existence of empty XML node attribute with XPathNavigator

Is there an easy way to detect the existence of an empty attribute on an XPat开发者_JAVA百科hNavigator XML node (e.g. <node> vs. <node attribute="">)? Node.GetAttribute returns an empty string either way. The only thing I can think of is checking the Node.OuterXML property, which seems like a really dumb approach.

(Note: the node won't actually be empty, so I can't just use Node.HasAttributes.)


You can use XPath:

elem.SelectSingleNode("@attribute")

This returns null, if the the attributte attribute doesn't exist, and another XPathNavigator with NodeType of Attribute and Value containing an empty string if the attribute exists, but is empty.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜