Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

DataSet.ReadXml Method (Stream, XmlReadMode)

Reads XML schema and data into the DataSet using the specified System.IO.Stream and XmlReadMode.

Namespace:  System.Data
Assembly:  System.Data (in System.Data.dll)
public XmlReadMode ReadXml(
	Stream stream,
	XmlReadMode mode
)

Parameters

stream
Type: System.IO.Stream

The Stream from which to read.

mode
Type: System.Data.XmlReadMode

One of the XmlReadMode values.

Return Value

Type: System.Data.XmlReadMode
The XmlReadMode used to read the data.

The ReadXml method provides a way to read either data only, or both data and schema into a DataSet from an XML document, whereas the ReadXmlSchema method reads only the schema. To read both data and schema, use one of the ReadXML overloads that includes the mode parameter, and set its value to ReadSchema.

The same is true for the WriteXml and WriteXmlSchema methods, respectively. To write XML data, or both schema and data from the DataSet, use the WriteXml method. To write just the schema, use the WriteXmlSchema method.

NoteNote:

When you use ReadXml and you set XmlReadMode to Diffgram, the content of the target DataSet and the original DataSet may differ because of how the diffgram is generated and processed. For more information on diffgrams, see DiffGrams (ADO.NET).

If an in-line schema is specified, the in-line schema is used to extend the existing relational structure prior to loading the data. If there are any conflicts (for example, the same column in the same table defined with different data types) an exception is raised.

If no in-line schema is specified, the relational structure is extended through inference, as necessary, according to the structure of the XML document. If the schema cannot be extended through inference in order to expose all data, an exception is raised.

NoteNote:

The DataSet does not associate an XML elementwith its corresponding DataColumn or DataTable when legal XML characters like ("_") are escaped in the serialized XML. The DataSet itself only escapes illegal XML characters in XML element names and hence can only consume the same. When legal characters in XML element name are escaped, the element is ignored while processing.

If the XML Schema for a DataSet includes targetNamespace, data may not be read, and you may encounter exceptions when calling ReadXml to load the DataSet with XML that contains elements with no qualifying namespace. To read unqualified elements, set elementFormDefault equal to "qualified" in your XML Schema as the following example demonstrates.

 <xsd:schema id="MyDataSet" 
    elementFormDefault="qualified" 
    targetNamespace="http://www.tempuri.org/MyDataSet.xsd" 
    xmlns="http://www.tempuri.org/MyDataSet.xsd" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
 </xsd:schema>
NoteNote:

If the schema for your DataSet contains elements of the same name, but different type, in the same namespace, an exception is thrown when you attempt to read the schema into the DataSet with ReadXml by specifying XmlReadMode.ReadSchema. This exception does not occur if you are using .NET Framework version 1.0.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.