In this chapter we showed the strong relationship and integration of data access and XML in the .NET framework. Specifically, the ADO.NET DataSet supports the reading and writing of both XML and XML schemas. In the absence of an XML schema definition, the DataSet can infer the schema information from data in an XML document that it reads.
From the XML side, the XmlDataDocument object provides the bridge between the relational world and the hierarchical XML world. The data within the XmlDataDocument can be accessed either as XML or as relational data. Changes in one view automatically appear in the other view. As a database developer, you decide the best way to access and manipulate your data at any time.
Both relational database access and XML data manipulation are broad topics, with many books dedicated to the technologies and tools of each. We couldn't cover anywhere near all these topics in this chapter or even in this book. The important thing to remember is that ADO.NET and the .NET XML objects have been designed to integrate and cooperate fully with each other.
Questions and Answers
Sometimes the .NET documentation refers to the XDR schema format, in addition to the standard XSD format. What is the XDR format?
| A1: |
The XSD format is the XML Schema Definition format that is a recognized standard of the World Wide Web Consortium (W3C), the organization that manages Web-related standards (www.w3c.org). While waiting for the XSD standard, Microsoft worked with a preliminary subset, called XDR (XML-Data Reduced), that it developed for defining XML schemas. Once the XSD standard was finalized in May 2001, Microsoft fully embraced and supported that standard. Although schemas that are written by the .NET Framework are saved only in the XSD format, schemas can be read in either the XSD or XDR format, thereby maintaining compatibility with older systems. The .NET Framework SDK also includes a tool, xsd.exe, that can (among other things) convert a schema from XDR to XSD format.
Can I find out exactly how ADO.NET automatically infers a schema from an XML document?
| A2: |
The algorithm is actually well documented on MSDN in the Visual Studio help files. Starting with the help topic Inferring DataSet Relational Structure from XML, you can find a summary of the schema inference process, along with specifics of the processes for tables, columns, and relationships. The limitations of the inference process are also described.
This chapter has shown how I can access the same set of data either relationally via the DataSet or hierarchically via the XmlDataDocument. Which is the right approach?
| A3: |
In brief, there is no "right" approach. It depends on where your data is coming from and what you want to do with it. The .NET Framework provides the flexibility to fetch data from wherever it is either a relational (tabular) data source or a hierarchical data source. The point is that "Data is XML is data." Regardless of the source, you can manipulate and/or save data as either relational or XML data, depending on your needs. An additional, nontechnical consideration might be your level of experience and knowledge. Even if both the data source and the resulting data need to be XML, if you aren't (yet) familiar enough with XML tools and technologies, you can still complete the task of manipulating the data by using tabular (DataSet and DataTable) techniques.