DataSet XML Methods

The ADO.NET DataSet stores information internally in a proprietary binary format that’s optimized for XML representation. This means that data can be retrieved in XML format seamlessly, without any data loss or conversion errors. Table 17-1 lists the DataSet methods that work with XML.

Table 17-1. ADO.NET DataSet XML methods

Method

Description

GetXml( )

Retrieves the XML representation of the data in the DataSet as a single string.

GetXmlSchema( )

Retrieves the XSD schema for the DataSet XML as a single string. No data is returned.

ReadXml( )

Reads XML data from a file or a TextReader, XmlReader, or Stream object, and uses it to populate the DataSet. The XML document can include an inline schema.

ReadXmlSchema( )

Reads an XML schema from a file or a TextReader, XmlReader, or Stream object, and uses it to configure the DataSet (for example, creating Constraint and DataColumn objects).

WriteXml( )

Writes the contents of the DataSet to a file or a TextWriter, XmlWriter, or Stream object. You can choose to write the schema inline.

WriteXmlSchema( )

Writes just the XSD schema describing the contents of the DataSet to a file or a TextWriter, XmlWriter, or Stream object.

InferXmlSchema( )

Infers the XML schema and applies it to the DataSet by reading through an XML document supplied by a file or a TextReader, XmlReader, or Stream object.

Tip

If you need to manipulate or serialize the XML, the best choice is the direct WriteXml( ) method. Using ...

Get ADO.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.