SUMMARY



SUMMARY

In this chapter we looked at the XmlAdapter and XML views that map relational tables from SQL Server to an XML schema and provide bidirectional queries and updates. XML views provide several advantages, including removing the need for custom mapping code.

We explored how XML views are a type of XML provider, and are implemented via a declarative mapping format. This mapping, known as three-part mapping, consists of three format types: XSD for the XML schema, RSD for the relational schema, and MSD for the mapping schema that maps between the relational and XML domains. These XML views are combined with XQuery commands to allow queries to be issued over different data sources such as (but not limited to) DBMSs like SQL Server. We also saw how the XmlViewSchema class represents a compiled XML view that can be used with an XmlCommand to return results as XML.

Next we further discussed the XmlAdapter class, which is an addition to the ADO.NET DataAdapter programming model—but for XML data rather than relational data. This extremely powerful class enables you to pull relational data from SQL Server, shape it into any XML structure via an XML view, and then fill an XPathDocument2 class that can subsequently be queried and edited. Most importantly, the changes to the XPathDocument2 can then be "pushed back" or updated to SQL Server via the XML view, which automatically generates all the necessary SQL statements to perform the inserts, updates, and deletes. This provides the extraordinary ability to transform relational data into XML; take advantage of the rich, expressive, and hierarchical data model; utilize other XML technologies such as XSLT and XML Web Services; and then synchronize the changes back to the SQL Server DBMS.

We then looked at the System.Data.SqlXml namespaces and at the set of classes that are the .NET Framework equivalents of the existing SQLXML 3.0 technology. In particular we looked at the XmlBulkLoad class, which has the ability to load data quickly and easily from an XML document into SQL Server through an XML view. In effect, this allows streaming updates of XML into SQL Server, whereas the other class we examined, the XmlAdapter, provides in-memory document updates. Both of these components use XML views to perform the updates.

We discussed the DBObject class, which provides cursor-like access into SQL Server, selecting a single row and then a single column within that row using simple XPath-like expressions. We also investigated the XmlRowsetAdapter, which provides a kind of "bulk load" function for use with a DataSet, taking advantage of the XML views technology. It can transform XML into multiple tables in a DataSet, via an XML view, in the same way as the XmlBulkload class updates SQL Server.

Finally we touched on the ASP.NET XmlDataSource control and other data source controls that can load XML data and expose it for data binding. This provides the ability to easily bind parts of an XML document to a Web application to display hierarchical data on a form such as a tree control or menu.

In the next and final chapter, we'll end with a look at XQuery and other XML features that integrate with SQL Server.