To leverage XML ( eXtensible Markeup Language ) features in ASP.NET, you have to reference the System.XML namespace. Take a look at some of the classes found in the namespace to get a birds eye view of XML with ASP.NET.
So today you are going to learn about the XmlTextReader class, in future articles I will cover the other commonly used classes.
Unlike the in-memory XmlDocument, the XmlTextReader parses the XML document in a forward-only stream. The benefits of reading the XML in a forward-only fashion is speed, but of course you will lose some functionality when comparing to the in-memory approach of the XmlDocument. If you are working with very big XML documents, you will find that the XmlDocemtn can bog things down when compared to the forward-only XmlTextReader. If you don’t require the extra functionality of the XmlDocument, use the XmlTextReader.
There are many properties and methods in the XmlTextReader, here’s a quick example that demonstrates reading a simple XML document with the XmlTextReader class. Let's take a look at a live demo and then I'll explain what's going on briefly.