Working with XML

Table of contents:

Introduction

ADO.NET and XML classes are tightly integrated in the .NET Framework. The DataSet can be filled with data or a schema from an XML stream or document. The DataSet can persist or serialize its data or schema to an XML stream or document. ADO synchronizes the DataSet with an XmlDataDocument . Data can be modified simultaneously using either class as needed; all changes made in one class are immediately reflected in the other class. This chapter focuses on XML support in ADO.NET and in SQL Server 2000.

The XML support in .NET is provided by integrated classes in five namespaces:

System.Xml

Contains classes that provide standards-based support for processing XML

System.Xml.Schema

Contains classes that provide standards-based support for XML Schema Definition (XSD) language schemas

System.Xml.Serialization

Contains classes that serialize objects into XML documents or streams

System.Xml.XPath

Contains classes that parse and evaluate XPath

System.Xml.Xsl

Contains classes that support Extensible Stylesheet Language (XSL) transformations

The DiffGram is an XML format that identifies current and original versions of data allowing the contents of a DataSet to be recreated accurately. The DiffGram allows you to identify the changes made to a DataSet since it was filled. The DataSet uses the DiffGram format to persist and to serialize its contents for transport across a network. Recipe 8.8 shows how to create a DiffGram of changes made to a DataSet .

SQL Server 2000 introduced support for retrieving the results of queries in XML format using the FOR XML clause. The XmlReader provides direct forward-only, read-only access to the XML result set stream from the SQL Server. Recipe 8.5 shows how to use the FOR XML clause to retrieve XML-format data from a SQL Server using an XmlReader .

The SQLXML managed classes expose SQLXML functionality that allows .NET applications to access XML data from SQL Server 2000, process the XML data, and update the SQL Server using an XML DiffGram representation of the data. SQLXML classes support template queries, an XML document containing one or more SQL queries or stored procedures, to execute. Recipe 8.10 shows how to use template queries.

OpenXML allows an XML document to be used in a SQL statement in the same way a table or view is used. Recipe 8.11 shows how to use OpenXML from ADO.NET.

Connecting to Data

Retrieving and Managing Data

Searching and Analyzing Data

Adding and Modifying Data

Copying and Transferring Data

Maintaining Database Integrity

Binding Data to .NET User Interfaces

Working with XML

Optimizing .NET Data Access

Enumerating and Maintaining Database Objects

Appendix A. Converting from C# to VB Syntax



ADO. NET Cookbook
ADO.NET 3.5 Cookbook (Cookbooks (OReilly))
ISBN: 0596101406
EAN: 2147483647
Year: 2002
Pages: 222
Authors: Bill Hamilton

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net