Design Goals for XML Classes in the .NET Framework

The XML classes in the .NET Framework have been designed to offer developers:

  • High productivity

  • Compliance with W3C standards

  • Extensibility

  • A pluggable architecture

  • High performance

  • Integration with ADO.NET

With the introduction of LINQ to XML, Microsoft aims to help developers be more productive by making programming with XML easier. LINQ to XML provides a query experience that is similar to SQL. With just a bit of study, a programmer can learn to write powerful queries in a few lines of code.

The XML classes in the .NET Framework were built with careful consideration of World Wide Web Consortium (W3C) recommendations. These XML classes allow processing XML data compliant with W3C recommendations. For example:

  • The XmlDocument class implements the W3C document object model (DOM) Level 1 Core and the DOM Level 2 Core recommendations.

  • The XmlReader and XmlWriter classes conform to the W3C XML 1.0 and namespaces in XML recommendations.

  • Schemas in the XmlSchemaSet class conform to the W3C XML schema Part 1, structures and XML schema Part 2, and datatypes recommendations.

  • Classes in the System.Xml.Xsl namespace support XSLT transformations that conform to the W3C XSLT version 1.0 recommendation.

The XML classes in the .NET Framework are designed to be extensible through the use of abstract base classes and virtual methods. This extensibility is illustrated by the XmlResolver class.

The XmlResolver class is an abstract class that resolves XML resources such as entities, import or export elements, and so on. The XmlUrlResolver and XmlSecureResolver classes are implementations of the XmlResolver class. You can create a customized version of the XmlResolver class by deriving from the XmlResolver class or any of its implementations. For example, you could create a derived class of the XmlUrlResolver class that stores the cache stream to the local disk.

A pluggable architecture is one in which components can utilize each other and, in many cases, be substituted for each other. The .NET Framework has such an architecture. Components that are based on abstract classes can be substituted for each other, and data can be streamed between them.

For example, a stream of XML from an XML Web service can be parsed with the XmlReader. The XmlReader can be used to create an XmlDocument, which in turn can be used to create an XmlNodeReader.

Another example is the use of different data stores, such as an XPathDocument or an XmlDocument, in the transformation of XML. These data stores can be transformed with the XslCompiledTransform class and the output can then be streamed either into another store or returned as a stream from an XML Web service.

To enable increased application performance, some of the XML classes in the .NET Framework have been designed to support a streaming-based model with the following characteristics:

  • Minimal caching for forward-only, pull-model parsing (XmlReader)

  • Forward-only validation (XmlReader)

  • Cursor style navigation that minimizes node creation to a single virtual node yet provides random access to the document (XPathNavigator). Note that this does not require a complete node tree to be built in memory as does the DOM.

For increased performance whenever XSLT processing is required, use the XPathDocument and XslCompiledTransform classes. XPathDocument is an optimized, read-only store for XPath queries designed to work efficiently with the XslCompiledTransform class.

Relational data and XML are brought together in the .NET Framework by a tight integration between the XML classes and ADO.NET.

The DataSet class is an in-memory cache of data retrieved from a database. The DataSet has the ability to read and write XML using the XmlReader and XmlWriter classes, to persist its internal relational schema structure as XML schemas (XSD), and to infer the schema structure of an XML document.