Megosztás a következőn keresztül:


Comparing XmlReader to SAX Reader

Like the Simple API for XML (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:

Advantage

Description

State Management

The 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 Streams

The pull model allows the client to put together multiple input streams. This is extremely complex to do in the push model.

Layering

The push model can be built on top of the pull model. The reverse is not true.

Extra String Copy Avoidance

Normally, 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 Processing

The 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).

See Also

Concepts

Reading XML with the XmlReader

Other Resources

Using the XmlReader Class