XmlReader
XmlReader
is an abstract base class that provides an event-based, read-only,
forward-only XML pull parser (I’ll discuss each of
these terms shortly). XmlReader has three concrete
subclasses, XmlTextReader,
XmlValidatingReader, and
XmlNodeReader, which enable you to read XML from a
file, a Stream, or an XmlNode.
You can also extend XmlReader to read other,
non-XML data formats, and deal with them as if they were XML
(you’ll learn how to do this in Chapter 4).
The base XmlReader
provides only the most essential functionality for reading XML
documents. It does not, for example, validate XML
(that’s what XmlValidatingReader
does) or expand XML entities into their respective character data
(though XmlTextReader does). This does not mean
that XML read from a text file cannot be validated at all; you can
validate XML from any source by using the
XmlValidatingReader constructor that takes an
XmlReader object as a parameter, as
I’ll demonstrate.
Here are those four terms I used to describe
XmlReader again, with a little explanation.
- Event-based
An event in a stream-based XML reader indicates the start or end of an XML node as it is read from the data stream. The event’s information is delivered to your application, and your application takes some action based on that information. In
XmlReader, events are delivered by queryingXmlReader’s properties after calling itsRead( )method.- Read-only
XmlReader, as its name implies, can only read XML. For writing XML, there is anXmlWriter ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access