Library tutorials & articles

What's new in System.Xml 2.0

Introduction, XML readers & writers

This article was originally published on DNJ Online
DNJ

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.

Comments

  1. 01 Jan 1999 at 00:00

    This thread is for discussions of What's new in System.Xml 2.0.

Leave a comment

Sign in or Join us (it's free).

AddThis

Related discussion

Related podcasts

  • Episode 10: LINQ

    K Scott leads us in a discussion of LINQ, including:

What is it
How introducing LINQ to .NET changed the framework
LINQ Providers
LINQ to XML
LINQ to SQL - how it’s different from EF, tips and tricks, when to use it

Links:

LINQpad
3rd Party LIN...

Related jobs

Events coming up

  • Dec 6

    Developing AJAX Web Applications with Castle Monorail

    London, United Kingdom

    Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!