Introduction

Can an XML stream be deconstructed using multiple nested XmlReader processes;

Can an XML stream be assembled from multiple nested XmlWriter processes.

Solving these problems makes the using of XmlSerializer possible when you are creating XML from objects.

Using the Code

The library contains two classes: XmlChunkReader and XmlChunkWriter.

XmlChunkReader can be created using XmlReader while it’s reading XML element nodes. It can be used as a standalone XmlReader, e.g., to perform a deserialization operation. When XmlChunkReader is closed, the main reader points to the next XML node. Using XmlChunkReader helps avoid such calls as ReadInnerXml.

XmlChunkWriter can be created using XmlWriter. It can be used as a standalone XmlWriter, e.g., to perform serialization of objects. When XmlChunkWriter is closed, the main XmlWriter is ready to continue writing XML data. Using XmlChunkWriter helps format data in the same manner and avoids writing of XML declaration instructions in the middle of XML.

The library also simplifies the implementation of the IXmlSerializable interface.

The source code can be easily adapted for .NET framework version 1.1.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

Comments and Discussions

I didn't try any other version of the framework, but below are the methods that I touched (1 added and 1 changed) in XmlChunkReader in order to get this to work in tandem with the serializers generated by the 4.5.1 framework. The one example provided by the author worked fine without these changes, but the first thing I tried myself (which used no attributes at all and was trivial) did not work. Thanks for providing this article. I found it useful. --Bern McCarty

Great implementation! I was always struggling with serializing arrays of an abstract type, but with these classes it can be achieved with relative ease ^^ (without using the XmlInclude or SoapInclude attributes).
Thanks for sharing!