开发者

How to test if a XML element has a text element inside?

I would like to know how could I test the fallowing situation:

<foo>
    <bla1>xxx</bla1>
    <bla2>yyy</bla2>
    <bla3>zzz</bla3>
</foo>

In the while(reader.Read()), I d开发者_如何学JAVArop in the XmlNodeType.Element when I'm in the foo and bla1, bla2, bla3... When drop in the .TextElement in the xxx, yyy, zzz. But can I test if the bla's will have a text value inside or not?

Thanks very much

Pedro Dusso


No, you can't as long as you are using an XmlReader.

The XmlReader class implements a forward-only cursor through an XML hieararchy. As such you can only operate on the XML node found at the current position.

In your case this means that you won't be able to check the contents of the "bla" nodes without first iterating through them.


If you are using an XmlTextReader you can use the property IsEmptyElement


Anything wrong with reader.HasValue? (or string.IsNullOrEmpty(reader.Value))?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜