5

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 drop 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

Pedro Dusso
  • 2,100
  • 9
  • 34
  • 64

3 Answers3

2

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.

Enrico Campidoglio
  • 56,676
  • 12
  • 126
  • 154
  • You are right, but I'm using the XmlTextReader in fact, sorry I did not write it before. – Pedro Dusso Oct 03 '10 at 21:43
  • The same principle is true for XmlTextReader. A forward-only cursor will only allow you to inspect the node currently being visited. If you want to query an XML hierarchy you'll have to load it into an in-memory DOM structure, such as the XmlDocument class or the XDocument class. – Enrico Campidoglio Oct 04 '10 at 12:47
  • Yeap... I got it. I will have to think about it. We are supposed to process a 700MB XML file, so I wont be able to load it in memory... Thanks anyway man! – Pedro Dusso Oct 05 '10 at 21:14
0

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

pierroz
  • 7,653
  • 9
  • 48
  • 60
0

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

smartcaveman
  • 41,281
  • 29
  • 127
  • 212