So far, you've worked exclusively with XML documents stored on disk or created as strings. But the XmlDataDocument class represents a third type of top-level DOM document. The main difference between an XmlDataDocument object and the XmlDocument or XPathDocument object is that an XmlDataDocument is closely tied to the DataSet class, so it lets you treat loaded XML data in a relational manner. You can populate the XmlDataDocument object via a DataSet. For example, the Web Form ch15-4.aspx uses a DataSet containing the Students table from the ClassRecords database. I dragged a SqlConnection and a SqlDataAdapter from the Toolbox onto the form design surface and configured the resulting SqlDataAdapter1 instance with a SQL query that returns all the fields from the Students table. When you right-click the SqlDataAdapter1 on that Web Form, you see the option to Generate Dataset. When you do that, you'll see the Generate Dataset dialog (see Figure 15.5).
Click the New radio button and enter the name ch15_dsClassRecords_students. Check the Add This DataSet to the Designer option. When you click ok, the designer generates a schema for the DataSet and a class and adds both to the current folder in the Solution Explorer. Double-click the Ch15_dsClassRecords_students.xsd item in the Solution Explorer to open the schema in the designer. You'll see the schema in Listing 15.7.
Was this article helpful?