This documentation is archived and is not being maintained.

Comparing XmlReader to SAX Reader

Like the SAX reader, the XmlReader is a forward-only, read-only cursor. It provides fast, non-cached stream access to the input. It can read a stream or a document. It allows the user to pull data, and skip records of no interest to the application. The big difference lies in the fact that the SAX model is a "push" model, where the parser pushes events to the application, notifying the application every time a new node has been read, while applications using XmlReader can pull nodes from the reader at will. The benefits of this pull model are in these areas:

AdvantageDescription
State ManagementThe push model requires the content handlers to build very complex state machines. The pull model client simplifies state management by a natural, top-down procedural refinement.
Multiple Input StreamsThe pull model allows the client to put together multiple input streams. This is extremely complex to do in the push model.
LayeringThe push model can be built on top of the pull model. The reverse is not true.
Extra String Copy AvoidanceNormally, the data is read from the parser buffer into the string object, which is then pushed to the client buffer. The pull model allows the client to give the parser a buffer into which the string is directly written.
Selective ProcessingThe push model notifies the client of each item, including attributes, processing instructions, and white space, while the pull model client can skip items, processing only those items that are of interest to the application. This allows for extremely efficient applications. Also, properties can be set in advance that affect how the XML stream is processed (For example, Normalization). For more information on skipping content, see Skipping Content with XmlReader.

See Also

Reading XML with the XmlReader | Current Node Position in XmlReader | Property Settings on XmlReader | Object Comparison Using XmlNameTable with XmlReader | Reading Attributes with XmlReader | Reading Element and Attribute Content | Skipping Content with XmlReader | EntityReference Reading and Expansion | Reading XML Data with XmlTextReader | Reading Node Trees with XmlNodeReader | Validating XML with XmlValidatingReader | Customized XML Reader Creation | XmlReader Class | XmlReader Members | XmlNodeReader Class | XmlNodeReader Members | XmlTextReader Class | XmlTextReader Members | XmlValidatingReader Class | XmlValidatingReader Members

Show: