What's new in System.Xml 2.0

writers

This article was originally published on DNJ Online
DNJ Online

While there have been many improvements and new features added to ADO.NET, the changes going on in the XML-related classes in version 2.0 have been even more dramatic. Through the XML InfoSet model defined by the World Wide Web Consortium (W3C), XML is evolving to become a universal data access technology that can represent both structured rowset data and hierarchical and unstructured information. As this view of XML, and the associated standards, have been emerging, so the classes in the System.Xml and its subsidiary namespaces have been changing to better accommodate the needs of developers and provide the best possible performance. The what follows is a brief overview of these changes and the associated techniques that the new classes enable when working with XML.

XML Readers and Writers

The XmlReader and XmlWriter classes in the System.Xml namespace are the common base classes that provide streaming access for reading and writing XML documents. In version 1.x, these classes are abstract, and you use the concrete classes such as XmlTextReader and XmlTextWriter to perform XML data access. However, in version 2.0, the approach has changed. Instead, you use the new XmlReaderSettings and XmlWriterSettings classes to define the behavior you want with regards to validation, white-space handling, indenting and so forth, and then generate instances of the XmlReader and XmlWriter classes that exhibit the required behavior.
This approach offers several advantages. It makes it is easier to pass instances of the classes to other routines in your applications in such a way that the consumer can add new behavior but not remove existing behavior. It also allows you to use them as streaming producer/consumer instances to pipeline XML between tiers of an application. And finally, it allows the Framework to make appropriate optimizations, such as not including validation code where this is not required, while supporting future extensibility of the classes.
The XmlReader also exhibits another useful new feature in that it can perform validation directly, without you having to create an XmlValidatingReader from it (as is the case in version 1.x). Furthermore, the XmlReader and XmlWriter now support all the CLR data types directly, allowing you read values from an XmlReader as typed data, and pass typed data instances directly to the XmlWriter, as shown below.

You might also like...

Comments

About the author

Alex Homer

Alex Homer United Kingdom

Alex spent most of his earlier working life as a technical salesman, and has had a love-hate relationship with computers that goes way back to the Sinclair Z80 and the Oric Atmos. In 1996 he ret...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Debuggers don't remove bugs. They only show them in slow motion.”