- Sams Teach Yourself XML in 21 Days, Third Edition
- Table of Contents
- About the Author
- Acknowledgments
- We Want to Hear from You!
- Introduction
- Part I: At a Glance
- Day 1. Welcome to XML
- All About Markup Languages
- All About XML
- Looking at XML in a Browser
- Working with XML Data Yourself
- Structuring Your Data
- Creating Well-Formed XML Documents
- Creating Valid XML Documents
- How XML Is Used in the Real World
- Online XML Resources
- Summary
- Q&A
- Workshop
- Day 2. Creating XML Documents
- Choosing an XML Editor
- Using XML Browsers
- Using XML Validators
- Creating XML Documents Piece by Piece
- Creating Prologs
- Creating an XML Declaration
- Creating XML Comments
- Creating Processing Instructions
- Creating Tags and Elements
- Creating CDATA Sections
- Handling Entities
- Summary
- Q&A
- Workshop
- Day 3. Creating Well-Formed XML Documents
- What Makes an XML Document Well-Formed?
- Creating an Example XML Document
- Understanding the Well-Formedness Constraints
- Using XML Namespaces
- Understanding XML Infosets
- Understanding Canonical XML
- Summary
- Q&A
- Workshop
- Day 4. Creating Valid XML Documents: DTDs
- All About DTDs
- Validating a Document by Using a DTD
- Creating Element Content Models
- Commenting a DTD
- Supporting External DTDs
- Handling Namespaces in DTDs
- Summary
- Q&A
- Workshop
- Declaring Attributes in DTDs
- Day 5. Handling Attributes and Entities in DTDs
- Specifying Default Values
- Specifying Attribute Types
- Handling Entities
- Summary
- Q&A
- Workshop
- Day 6. Creating Valid XML Documents: XML Schemas
- Using XML Schema Tools
- Creating XML Schemas
- Dissecting an XML Schema
- The Built-in XML Schema Elements
- Creating Elements and Types
- Specifying a Number of Elements
- Specifying Element Default Values
- Creating Attributes
- Summary
- Q&A
- Workshop
- Day 7. Creating Types in XML Schemas
- Restricting Simple Types by Using XML Schema Facets
- Creating XML Schema Choices
- Using Anonymous Type Definitions
- Declaring Empty Elements
- Declaring Mixed-Content Elements
- Grouping Elements Together
- Grouping Attributes Together
- Declaring all Groups
- Handling Namespaces in Schemas
- Annotating an XML Schema
- Summary
- Q&A
- Workshop
- Part I. In Review
- Well-Formed Documents
- Valid Documents
- Part II: At a Glance
- Day 8. Formatting XML by Using Cascading Style Sheets
- Our Sample XML Document
- Introducing CSS
- Connecting CSS Style Sheets and XML Documents
- Creating Style Sheet Selectors
- Using Inline Styles
- Creating Style Rule Specifications in Style Sheets
- Summary
- Q&A
- Workshop
- Day 9. Formatting XML by Using XSLT
- Introducing XSLT
- Transforming XML by Using XSLT
- Writing XSLT Style Sheets
- Using <xsl:apply-templates>
- Using <xsl:value-of> and <xsl:for-each>
- Matching Nodes by Using the match Attribute
- Working with the select Attribute and XPath
- Using <xsl:copy>
- Using <xsl:if>
- Using <xsl:choose>
- Specifying the Output Document Type
- Summary
- Q&A
- Workshop
- Day 10. Working with XSL Formatting Objects
- Introducing XSL-FO
- Using XSL-FO
- Using XSL Formatting Objects and Properties
- Building an XSL-FO Document
- Handling Inline Formatting
- Formatting Lists
- Formatting Tables
- Summary
- Q&A
- Workshop
- Part II. In Review
- Using CSS
- Using XSLT
- Using XSL-FO
- Part III: At a Glance
- Day 11. Extending HTML with XHTML
- Why XHTML?
- Writing XHTML Documents
- Validating XHTML Documents
- The Basic XHTML Elements
- Organizing Text
- Formatting Text
- Selecting Fonts: <font>
- Comments: <!-->
- Summary
- Q&A
- Workshop
- Day 12. Putting XHTML to Work
- Creating Hyperlinks: <a>
- Linking to Other Documents: <link>
- Handling Images: <img>
- Creating Frame Documents: <frameset>
- Creating Frames: <frame>
- Creating Embedded Style Sheets: <style>
- Formatting Tables: <table>
- Creating Table Rows: <tr>
- Formatting Table Headers: <th>
- Formatting Table Data: <td>
- Extending XHTML
- Summary
- Q&A
- Workshop
- Day 13. Creating Graphics and Multimedia: SVG and SMIL
- Introducing SVG
- Creating an SVG Document
- Creating Rectangles
- Adobe's SVG Viewer
- Using CSS Styles
- Creating Circles
- Creating Ellipses
- Creating Lines
- Creating Polylines
- Creating Polygons
- Creating Text
- Creating Gradients
- Creating Paths
- Creating Text Paths
- Creating Groups and Transformations
- Creating Animation
- Creating Links
- Creating Scripts
- Embedding SVG in HTML
- Introducing SMIL
- Summary
- Q&A
- Workshop
- Day 14. Handling XLinks, XPointers, and XForms
- Introducing XLinks
- Beyond Simple XLinks
- Introducing XPointers
- Introducing XBase
- Introducing XForms
- Summary
- Workshop
- Part III. In Review
- Part IV: At a Glance
- Day 15. Using JavaScript and XML
- Introducing the W3C DOM
- Introducing the DOM Objects
- Working with the XML DOM in JavaScript
- Searching for Elements by Name
- Reading Attribute Values
- Getting All XML Data from a Document
- Validating XML Documents by Using DTDs
- Summary
- Q&A
- Workshop
- Day 16. Using Java and .NET: DOM
- Using Java to Read XML Data
- Finding Elements by Name
- Creating an XML Browser by Using Java
- Navigating Through XML Documents
- Writing XML by Using Java
- Summary
- Q&A
- Workshop
- Day 17. Using Java and .NET: SAX
- An Overview of SAX
- Using SAX
- Using SAX to Find Elements by Name
- Creating an XML Browser by Using Java and SAX
- Navigating Through XML Documents by Using SAX
- Writing XML by Using Java and SAX
- Summary
- Q&A
- Workshop
- Day 18. Working with SOAP and RDF
- Introducing SOAP
- A SOAP Example in .NET
- A SOAP Example in Java
- Introducing RDF
- Summary
- Q&A
- Workshop
- Part IV. In Review
- Part V: At a Glance
- Day 19. Handling XML Data Binding
- Introducing DSOs
- Binding HTML Elements to HTML Data
- Binding HTML Elements to XML Data
- Binding HTML Tables to XML Data
- Accessing Individual Data Fields
- Binding HTML Elements to XML Data by Using the XML DSO
- Binding HTML Tables to XML Data by Using the XML DSO
- Searching XML Data by Using a DSO and JavaScript
- Handling Hierarchical XML Data
- Summary
- Q&A
- Workshop
- Day 20. Working with XML and Databases
- XML, Databases, and ASP
- Storing Databases as XML
- Using XPath with a Database
- Introducing XQuery
- Summary
- Q&A
- Workshop
- Day 21. Handling XML in .NET
- Creating and Editing an XML Document in .NET
- From XML to Databases and Back
- Reading and Writing XML in .NET Code
- Using XML Controls to Display Formatted XML
- Creating XML Web Services
- Summary
- Q&A
- Workshop
- Part V. In Review
- Appendix A. Quiz Answers
- Quiz Answers for Day 1
- Quiz Answers for Day 2
- Quiz Answers for Day 3
- Quiz Answers for Day 4
- Quiz Answers for Day 5
- Quiz Answers for Day 6
- Quiz Answers for Day 7
- Quiz Answers for Day 8
- Quiz Answers for Day 9
- Quiz Answers for Day 10
- Quiz Answers for Day 11
- Quiz Answers for Day 12
- Quiz Answers for Day 13
- Quiz Answers for Day 14
- Quiz Answers for Day 15
- Quiz Answers for Day 16
- Quiz Answers for Day 17
- Quiz Answers for Day 18
- Quiz Answers for Day 19
- Quiz Answers for Day 20
- Quiz Answers for Day 21
Storing Databases as XML
Microsoft has added a great deal of XML support to its database products—far more than any other provider out there, so like it or not, we're in Microsoft territory here. In particular, Microsoft's ADO.NET database protocol uses XML to send data back and forth between databases and applications.
For example, let's examine how to use a Visual Basic .NET application to interact with a database by using SQL Server and see how the data is actually transferred with XML. Figure 20.3 shows a step in the process of creating a new Visual Basic .NET Windows application named ch20_03.
Figure 20.3 Creating a Visual Basic .NET Windows application.
Figure 20.4 shows the new Windows application that we create, complete with the two buttons Store XML Data and Read XML Data. Because ADO.NET datasets are sent back and forth by using XML, we can create a dataset when the user clicks the Store XML Data button and store it in XML; then we can create a new dataset by using that XML data when the user clicks the Read XML Data button. After we create the second dataset, we'll bind that data to a data grid control, so let's add a data grid to the Windows form now, as shown in Figure 20.4.
Figure 20.4 Creating the ch20_03 application.
We'll need a connection to a data source, and in this case we can use Microsoft SQL Server, which is often used in .NET data work. In this case, we'll use a data connection to the pubs SQL Server sample database and extract the data from the employee table in that database. To create that data connection, right-click the Data Connections icon in the Visual Basic .NET Server Explorer (the tab for this tool appears at the left in the Visual Basic .NET development environment, as shown in Figure 20.4), and select the Add Connection item; or select Tools, Connect to Database. In either case, the Data Link Properties dialog box appears.
In the Data Link Properties dialog box, enter the name of the server you want to work with, as well as the login name and password, if applicable—or select the Windows NT integrated security option if your application and SQL Server are on the same machine. Next, choose a database to work with by using either the Select the Database on the Server option or the Attach a Database File as a Database Name option. In this case, we'll use the pubs sample database that comes with SQL Server, so let's select the first option and choose the pubs database. Then you need to click OK to close this dialog box.
This new data connection appears in the Visual Basic .NET Server Explorer. Now that we've created a data connection to the pubs database, we can drag an OleDbDataAdapter control from the Visual Basic .NET toolbox to the Visual Basic .NET form we're creating; this opens the Data Adapter Configuration Wizard. You need to click Next to move to the second pane of this wizard, as shown in Figure 20.5. Then select the data connection to the pubs database (it is named STEVE.pubs.dbo on the machine this example is being developed on, as shown in the figure), and then click Next twice, to open the Data Adapter Configuration Wizard's fourth pane.
Figure 20.5 Connecting to the pubs database.
To indicate that you want to connect to the employee table, you need to click the Query Builder button in the fourth pane of the wizard, select the employee item in the Add Table dialog box that appears, click the Add button and then the Close button. The Query Builder appears, as shown in Figure 20.6.
Figure 20.6 The Query Builder.
The Query Builder lets us generate the SQL needed to extract the employee table from the pubs database. To generate that SQL, click the All Columns check box in the employee table's window, as shown in Figure 20.6, and then click OK. As you can see in the Data Adapter Configuration Wizard in Figure 20.7, this generates the following SQL statement:
SELECT employee.* FROM employee"
Figure 20.7 A new SQL statement in the Query Builder.
Now you need to click Next and then Finish to complete the creation of the data adapter you'll need to connect to the employee table. This creates both an OleDbDataAdapter object and an OleDbConnection object.
The connection object will maintain the connection to SQL Server, and the adapter object will be responsible for activating the connection and retrieving data. Both connection and adapter objects are important in ADO.NET work. Table 20.1 lists the significant properties of the OleDbDataAdapter objects, and Table 20.2 lists the significant methods of these objects. Table 20.3 lists the significant properties of the OleDbConnection objects, and Table 20.4 lists the significant methods of these objects.
Table 20.1. Significant Public Properties of OleDbDataAdapter Objects
Property |
Description |
DeleteCommand |
Returns or sets the SQL for deleting records. |
InsertCommand |
Returns or sets the SQL for inserting new records. |
SelectCommand |
Returns or sets the SQL for selecting records. |
UpdateCommand |
Returns or sets the SQL for updating records. |
Table 20.2. Significant Public Methods of OleDbDataAdapter Objects
Method |
Description |
Fill |
Adds rows to or refreshes rows in a dataset to make them match the rows in a data store. |
Table 20.3. Significant Public Properties of OleDbConnection Objects
Property |
Description |
ConnectionString |
Returns or sets the connection string to open a database. |
ConnectionTimeout |
Returns the time to wait while trying to make a connection (in seconds). |
Database |
Returns the name of the database to open. |
DataSource |
Returns the data source (usually the location and filename of the file to open). |
Provider |
Returns the OLE DB provider's name. |
ServerVersion |
Returns the version of the server. |
State |
Returns the connection's current state. |
Table 20.4. Significant Public Methods of OleDbConnection Objects
Method |
Description |
BeginTransaction |
Starts a database transaction. |
ChangeDatabase |
Changes the current database. |
Close |
Closes the connection to the data provider. |
CreateCommand |
Creates an OleDbCommand object for this connection. |
GetOleDbSchemaTable |
Returns the current schema table. |
Open |
Opens a database connection. |
We're going to connect the employee table to a dataset object so we can access that table's data. To create a dataset based on the data supplied by our OleDeDataAdapter object, you need to select Data, Generate Dataset in Visual Basic .NET. This opens the Generate Dataset dialog box, and you need to click OK to create a new dataset object, DataSet11 (that is, the first object of the automatically generated DataSet1 class). Datasets act as repositories of data in .NET, and they give us direct local access to the data from a data provider. Table 20.5 lists the significant properties of the DataSet class, and Table 20.6 lists the significant methods of the DataSet class.
Table 20.5. Significant Public Properties of the DataSet Class
Property |
Description |
DataSetName |
Returns or sets the name of the dataset. |
EnforceConstraints |
Returns or sets whether constraint rules are enforced. |
HasErrors |
Indicates whether there are errors in any row in the table. |
Relations |
Gets relation objects that link tables. |
Tables |
Returns tables in the dataset. |
Table 20.6. Significant Public Methods of the DataSet Class
Method |
Description |
AcceptChanges |
Accepts (commits) the changes made to the dataset. |
Clear |
Clears the dataset by removing all rows in all tables. |
Copy |
Copies the dataset. |
GetChanges |
Returns a dataset that contains all changes made to the current dataset. |
GetXml |
Returns the data in the dataset in XML. |
GetXmlSchema |
Returns the XSD schema for the dataset. |
HasChanges |
Indicates whether the dataset has changes that have not yet been accepted. |
Merge |
Merges this dataset with another dataset. |
ReadXml |
Reads data into a dataset from XML. |
ReadXmlSchema |
Reads an XML schema into a dataset. |
RejectChanges |
Rolls back the changes made to the dataset since it was created or since the AcceptChanges method was last called. |
Reset |
Resets the dataset to the original state. |
WriteXml |
Writes the dataset's schema and data to XML. |
WriteXmlSchema |
Writes the dataset schema to XML. |
Now double-click the Store XML Data button to open the handler function that holds the code that will be executed when the button is clicked:
Private Sub Button1_Click(ByVal sender As System.Object, . . . End Sub
Begin this code by using the data adapter object to fill the dataset object with data from the employee table:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click DataSet11.Clear() OleDbDataAdapter1.Fill(DataSet11) . . . End Sub
Next store the employee table from the dataset as an XML document, data.xml, by using the dataset's WriteXml method:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click DataSet11.Clear() OleDbDataAdapter1.Fill(DataSet11) DataSet11.WriteXml("data.xml") . . . End Sub
In fact, ADO.NET uses XML and XML schemas to transfer data in .NET, so write the current schema out to a file, dataSchema.xml, as well, by using the WriteXmlSchema method:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click DataSet11.Clear() OleDbDataAdapter1.Fill(DataSet11) DataSet11.WriteXml("data.xml") DataSet11.WriteXmlSchema("dataSchema.xml") End Sub
Now you'll read this XML back in and use it to create a new dataset object. First, create that dataset object by adding this code to the handler method that is called when the Read XML Data button is clicked:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2. Click Dim ds As New DataSet() . . . End Sub
Now use this dataset object's ReadXML method to read the XML document that holds the entire employee table:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim ds As New DataSet() ds.ReadXml("data.xml") . . . End Sub
Because you've read the XML holding the employee table back in, bind it to your DataGrid control:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim ds As New DataSet() ds.ReadXml("data.xml") DataGrid1.SetDataBinding(ds, "employee") End Sub
The DataGrid class lets us display entire database tables in .NET applications, and it's designed to be used in data-aware applications. Table 20.7 lists the significant properties of the DataGrid class, and Table 20.8 lists the significant methods of this class.
Table 20.7. Significant Public Properties of the DataGrid Class
Property |
Description |
AllowNavigation |
Returns or sets whether navigation is allowed in the data grid. |
AllowSorting |
Returns or sets whether the grid can be sorted when the user clicks a column header. |
AlternatingBackColor |
Returns or sets the background color used in alternating rows. |
BackColor |
Returns or sets the background color of the data grid. |
BackgroundColor |
Returns or sets the color of the nondata sections of the data grid. |
BorderStyle |
Returns or sets the data grid's border style. |
CaptionBackColor |
Returns or sets the caption's background color. |
CaptionFont |
Returns or sets the caption's font. |
CaptionForeColor |
Returns or sets the caption's foreground color. |
CaptionText |
Returns or sets the caption's text. |
CaptionVisible |
Returns or sets whether the caption is visible. |
ColumnHeadersVisible |
Returns or sets whether the parent rows of a table are visible. |
CurrentCell |
Returns or sets which cell has the focus. |
CurrentRowIndex |
Returns or sets the index of the selected row. |
DataMember |
Returns or sets the table or list of data the data grid should display. |
DataSource |
Returns or sets the data grid's data source, such as a dataset. |
FirstVisibleColumn |
Returns the index of the first column visible in the grid. |
FlatMode |
Returns or sets whether the data grid should be shown flat. |
ForeColor |
Returns or sets the foreground color used in the data grid. |
GridLineColor |
Returns or sets the color of grid lines. |
GridLineStyle |
Returns or sets the grid line style. |
HeaderBackColor |
Returns or sets the background color of headers. |
HeaderFont |
Returns or sets the font used for headers. |
HeaderForeColor |
Returns or sets the foreground color of headers. |
Item |
Returns or sets the value in a particular cell. |
LinkColor |
Returns or sets the color of links to child tables. |
LinkHoverColor |
Returns or sets the color of links to child tables when the mouse moves over it. |
ParentRowsBackColor |
Returns or sets the background color of parent rows. |
ParentRowsForeColor |
Returns or sets the foreground color of parent rows. |
ParentRowsLabelStyle |
Returns or sets the style for parent row labels. |
ParentRowsVisible |
Returns or sets whether parent rows are visible. |
PreferredColumnWidth |
Returns or sets the width of the grid columns (in pixels). |
PreferredRowHeight |
Returns or sets the preferred row height. |
ReadOnly |
Returns or sets whether the grid is read-only. |
RowHeadersVisible |
Returns or sets whether row headers are visible. |
RowHeaderWidth |
Returns or sets the width of row headers. |
SelectionBackColor |
Returns or sets the selected cell's background color. |
SelectionForeColor |
Returns or sets the selected cell's foreground color. |
TableStyles |
Returns the table styles in the data grid. |
VisibleColumnCount |
Returns the number of visible columns. |
VisibleRowCount |
Returns the number of visible rows. |
Table 20.8. Significant Public Methods of the DataGrid Class
Method |
Description |
BeginEdit |
Makes the data grid allow editing. |
Collapse |
Collapses child table relations. |
EndEdit |
Ends editing operations. |
Expand |
Displays child relations. |
HitTest |
Coordinates the mouse position with points in the data grid. |
IsExpanded |
Returns whether a row is expanded or collapsed. |
IsSelected |
Returns whether a row is selected. |
NavigateBack |
Navigates to the previous table that was shown in the grid. |
NavigateTo |
Navigates to a specific table. |
Select |
Makes a selection. |
SetDataBinding |
Sets both the DataSource and DataMember properties. This method is used at runtime. |
UnSelect |
Deselects a row. |
Now run this application by selecting Debug, Start. Then, when you click the Store XML Data button, the employee table is stored in an XML document on disk; when you click the Read XML Data button, that XML document is read back into a new dataset object, which is bound to the DataGrid control in this application. Figure 20.8 shows the results, with the employees table, fresh from your XML document, appearing in the data grid.
Figure 20.8 Writing a database table to XML and reading it back in.
Here's what the employee table looks like as stored in XML in your XML document (note that each employee's data is stored in an element named <employee>):
<?xml version="1.0" standalone="yes"?> <DataSet1 xmlns="http://www.tempuri.org/DataSet1.xsd"> <employee> <emp_id>PMA42628M</emp_id> <fname>Paolo</fname> <minit>M</minit> <lname>Accorti</lname> <job_id>13</job_id> <job_lvl>35</job_lvl> <pub_id>0877</pub_id> <hire_date>1992-08-27T00:00:00.0000000-04:00</hire_date> </employee> <employee> <emp_id>PSA89086M</emp_id> <fname>Pedro</fname> <minit>S</minit> <lname>Afonso</lname> <job_id>14</job_id> <job_lvl>89</job_lvl> <pub_id>1389</pub_id> <hire_date>1990-12-24T00:00:00.0000000-05:00</hire_date> </employee> <employee> <emp_id>VPA30890F</emp_id> <fname>Victoria</fname> <minit>P</minit> <lname>Ashworth</lname> <job_id>6</job_id> <job_lvl>140</job_lvl> <pub_id>0877</pub_id> <hire_date>1990-09-13T00:00:00.0000000-04:00</hire_date> </employee> <employee> <emp_id>H-B39728F</emp_id> <fname>Helen</fname> <minit> </minit> <lname>Bennett</lname> <job_id>12</job_id> <job_lvl>35</job_lvl> <pub_id>0877</pub_id> <hire_date>1989-09-21T00:00:00.0000000-04:00</hire_date> </employee> . . .
Here's what the XML schema for this table looks like:
<?xml version="1.0" standalone="yes"?> <xs:schema id="DataSet1" targetNamespace="http://www.tempuri.org/DataSet1.xsd" xmlns="http://www.tempuri.org/DataSet1.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified"> <xs:element name="DataSet1" msdata:IsDataSet="true"> <xs:complexType> <xs:choice maxOccurs="unbounded"> <xs:element name="authors"> <xs:complexType> <xs:sequence> <xs:element name="au_id" type="xs:string" /> <xs:element name="au_lname" type="xs:string" /> <xs:element name="au_fname" type="xs:string" /> <xs:element name="phone" type="xs:string" /> <xs:element name="address" type="xs:string" minOccurs="0" /> <xs:element name="city" type="xs:string" minOccurs="0" /> <xs:element name="state" type="xs:string" minOccurs="0" /> <xs:element name="zip" type="xs:string" minOccurs="0" /> <xs:element name="contract" type="xs:boolean" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="employee"> <xs:complexType> <xs:sequence> <xs:element name="emp_id" type="xs:string" minOccurs="0" /> <xs:element name="fname" type="xs:string" minOccurs="0" /> <xs:element name="minit" type="xs:string" minOccurs="0" /> <xs:element name="lname" type="xs:string" minOccurs="0" /> <xs:element name="job_id" type="xs:short" minOccurs="0" /> <xs:element name="job_lvl" type="xs:unsignedByte" minOccurs="0" /> <xs:element name="pub_id" type="xs:string" minOccurs="0" /> <xs:element name="hire_date" type="xs:dateTime" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> <xs:unique name="Constraint1" msdata:PrimaryKey="true"> <xs:selector xpath=".//mstns:authors" /> <xs:field xpath="mstns:au_id" /> </xs:unique> </xs:element> </xs:schema>
This XML document and XML schema show the actual way that data is transmitted from database to .NET application and back again by using ADO.NET. Listing 20.2 shows the code we've written for this example.
Example 20.2. Button-Handling Code in the ch20_03 Project (from Form1.vb in the ch20_03 Project)
Public Class Form1 Inherits System.Windows.Forms.Form . . . Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click DataSet11.Clear() OleDbDataAdapter1.Fill(DataSet11) DataSet11.WriteXml("data.xml") DataSet11.WriteXmlSchema("dataSchema.xml") End Sub Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click Dim ds As New DataSet ds.ReadXml("data.xml") DataGrid1.SetDataBinding(ds, "employee") End Sub End Class