Chapter 13

In a few short years, XML has grown from an obscure specification into the world鈥檚 de facto data language. XML stands for Extensible Markup Language. Whereas HTML is designed to express appearance, XML is designed to express raw information absent any implied notion about how the data should be rendered. It鈥檚 a simple language that is entirely text based, making it particularly well suited to travel over text-based protocols such as HTTP, and that has no predefined tags as HTML does. XML provides the rules. You provide the rest.

XML finds several applications in business and, increasingly, in everyday life. It provides a common data format for companies that want to exchange documents. It鈥檚 used by Web services to encode messages and data in a platform-independent manner. It鈥檚 even used to build Web sites, where it serves as a tool for cleanly separating content from appearance.

There鈥檚 little remarkable about XML in and of itself. What makes XML important is the fact that the computer industry has accepted it as a standard, and as such numerous tools are available for reading and writing XML. If someone hands you a large free-formatted text file containing thousands of records and your job is to get the records into a database, you鈥檒l probably end up writing a parser to extract the records from the file and write them to the database. If the text file is an XML file, your job is much simpler. You can use one of the many XML parsers already available to read the records. XML doesn鈥檛 make your life easier because it鈥檚 a great language. It makes your life easier because tools for reading, writing, and manipulating XML data are almost as common as word processors.

When it comes to handling XML, nothing rivals the .NET Framework class library (FCL) for ease of use. A few simple statements will read an entire XML file and write its contents to a database, or query a database and write out the results as XML. It鈥檚 equally easy to perform XPath queries on XML documents or convert XML into HTML on the fly using XSL transformations.

This chapter is about the XML support in the FCL. A comprehensive treatment of the subject could easily fill 200 pages or more, so I鈥檒l attempt to strike a reasonable balance between detail and succinctness. In the pages that follow, you鈥檒l learn about the classes and namespaces that form the cornerstone for the FCL鈥檚 XML support. Before we start slinging code, however, let鈥檚 take a brief look at XML itself.