0672321300
Using the XML Classes
This article is excerpted from Chapter 13, "Integrating with the Enterprise," from Building Distributed Applications with VB.NET, by Dan Fox (ISBN 0672321300). It assumes the reader has some experience with VB, the Windows environment, event-based programming, basic HTML, and scripting. This material is based on the Beta2 release version of Microsoft's .NET technology.
As is obvious by now, XML is ingrained in .NET from configuration and files to the protocol for Web Services to acting as the data store for ADO.NET DataSet objects. Of course, these particular uses of XML highlight its self-describing and flexible nature. As a result, many organizations use XML to pass documents and data both within the organization and between trading partners and vendors. The ubiquitous nature of these exchanges means that sooner or later, developers will need to read and write XML documents, transform them with XSL, and validate them using XML schemas. This section will discuss the support in the Services Framework for working with XML in these ways.
At the highest level, the classes used to manipulate XML in the Services Framework are included in the System.Xml namespaces shown in Table 13.1.
Table 13.1 XML Namespaces and their uses.
Namespace |
Description |
System.Xml |
Contains the core XML classes to read and write XML documents and map the document to the Document Object Model (DOM). |
System.Xml.Schema |
Contains classes to work with XSD schemas and validate documents. |
System.Xml.Serialization |
Contains objects that enable classes to be serialized to XML. |
System.Xml.XPath |
Contains classes that allow you to navigate XML documents using XPath. |
System.Xml.Xsl |
Contains classes that allow you to transform documents using XSL stylesheets. |
As you can tell from the descriptions of the namespaces, the System.Xml namespace collectively supports the W3C standards XML 1.0 and DTDs, XML namespaces (http://www.w3.org/TR/REC-xml-names/), XML schemas (http://www.w3.org/TR/xmlschema-1/), XPath expressions (http://www.w3.org/TR/xpath), XSL transformations (http://www.w3.org/TR/xslt), DOM Level 2 Core (http://www.w3.org/TR/DOM-Level-2/), and SOAP 1.1.
NOTE
Developers familiar with working with XML documents in the COM world will no doubt have used the MSXML parser to programmatically manipulate documents. For those developers, the System.Xml classes will seem familiar because they both map to the DOM and because System.Xml was modeled after MSXML. However, the Services Framework implementation includes better standards compliance and a simpler programming model (especially for streamed access) that should make life easier. That being said, you can continue to use MSXML through COM Interop, although I think you'll find that porting code that works with the DOM will be relatively simple, while rewriting code that uses SAX, the Simple API for XML introduced in MSXML 3.0, will make for a more straightforward and efficient application.
To give you an overview of how the System.Xml namespace provides standards-based support for working with XML, this discussion will include dealing with streamed access to XML documents, manipulating XML documents with the DOM, handling XML schemas, and using XML serialization.