Parsing XML Fragments

The XmlTextReader class provides the basic set of functionalities to process any XML data coming from a disk file, a stream, or a URL. This kind of reader works sequentially, reading one node after the next, and does not deliberately provide any ad hoc search function to parse only a particular subtree.

In the .NET Framework, to process only fragments of XML data, excerpted from a variety of sources, you can take one of two routes. You can initialize the text reader with the XML string that represents the fragment, or you can use another, more specific, reader class—the XmlNodeReader class.

The XmlNodeReader class works on the subtree rooted in the XmlNode object passed to the class constructor. A living instance of an ...

Get Applied XML Programming for Microsoft® .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.