.NET contains an entire XML framework. This framework is made up of several classes that make it easy for you to implement and work with XML in your applications. Because .NET is so reliant on XML, Microsoft spent a great deal of time making these classes robust, easy to use, and very performant. As I have said before, these classes all follow the W3C specification for XML and they are an evolution to MSXML, which you might have already used.
Much of .NET actually uses XML for its native data representation. Examples of this can be seen in ASP.NET, Web services (which rely on the Simple Object Access Protocol, or SOAP), and you can even see XML in the automatic source code comments that are added when you create classes with Visual Studio.NET. XML is also an integral part of ADO.NET and SQL Server 2000, both of which are discussed in detail in Chapter 10.
The .NET XML classes enable you to easily work with relational data and hierarchical data. The classes provide a unified programming model.
The .NET XML framework can be found in several namespaces. The core types are contained in System.XML. The XPath and XSLT types can be found in System.Xml.XPath and System.Xml.Xsl. To use these classes you must import the correct names spaces through the using directive as follows :
At the core of the .NET framework XML classes are two abstract classes: XmlReader and XmlWriter . XmlReader provides a fast, forward-only, read-only cursor for processing an XML document stream. XmlWriter provides an interface for producing XML document streams that conform to the W3C's XML recommendations. Applications that need to process XML documents use XmlReader , whereas applications that want to create XML documents use XmlWriter . Both classes imply a streaming model that doesn't require an expensive in-memory cache. This makes them both attractive alternatives to the classic Document Object Model (DOM) approach.
The XmlReader and XmlWriter classes are abstract base classes. They define functionality that all derived classes must support. At present, three implementations of XmlReader are included in the .NET framework: XmlTextReader , XmlNodeReader , and XmlReader . Two implementations of XmlWriter are in the .NET framework. They are XmlTextWriter and XmlNodeWriter . The XmlTextReader and XmlTextWriter classes support reading from and writing to text-based streams. XmlNodeReader and XmlNodeWriter are used for in-memory DOM trees. One of the biggest advantages of this design is that custom readers and writers can be developed to extend the built-in functionality. I expect to see many of these extended classes appear on the Internet and in newsgroups as developers extend the classes to meet their needs and share the classes with others.