Synopsis
DataSet.ReadXml(Stream xmlSource
);
DataSet.ReadXml(String xmlSource
);
DataSet.ReadXml(TextReader xmlSource
);
DataSet.ReadXml(XmlReader xmlSource
);
DataSet.ReadXml(Stream xmlSource
, XmlReadMode xrm
);
DataSet.ReadXml(String xmlSource
, XmlReadMode xrm
);
DataSet.ReadXml(TextReader xmlSource
, XmlReadMode xrm
);
DataSet.ReadXml(XmlReader xmlSource
, XmlReadMode xrm
);
Reads XML schema information and data from the specified source into
the DataSet
.
Parameters
-
xmlSource
A Stream
, filename, TextReader
,
or XmlReader
containing the XML to read the schema
and data from.
-
xrm
One of the
XmlReadMode
enumeration values described in
Table 22-15.
Table 22-15. XmlReadMode enumeration
Value
|
Description
|
Auto
|
Sets the XmlReadMode based on the data contained
in the source. If the data is a Diffgram , the
XmlReadMode is set to Diffgram .
If either the DataSet has a schema defined or the
XML document contains an inline XSD schema, the
XmlReadMode is set to
ReadSchema . If the DataSet
doesn’t have a schema and the XML document
doesn’t contain an inline XSD schema, the
XmlReadMode is set to
InferSchema . This is the default value.
|
Diffgram
|
Applies the changes specified by the Diffgram to
the DataSet . The Diffgram for
the source DataSet should be generated using the
WriteXml() method specifying
XmlWriteMode of Diffgram . An
exception is thrown if the DataSet
doesn’t have the same schema as
DataSet for which the DiffGram
was generated.
|
Fragment
|
Reads an XML document using the default namespace as the inline
schema.
|
IgnoreSchema
|
Reads the XML into the DataSet schema, ignoring
any inline schema that might be present.
|
InferSchema
|
Reads the XML into the DataSet , inferring a schema
and ignoring any inline schema that might be present. If the
DataSet contains a schema that conflicts with the
inferred schema, an exception is thrown.
|
ReadSchema
|
Reads the inline schema and loads data into the
DataSet . If the DataSet
contains a schema for tables defined in the inline schema, an
exception is thrown.
|
Example
The following example shows how to use the ReadXml( )
and WriteXml( )
methods to read and
write the XML representation of a DataSet
along
with the DataSet
schema:
DataSet ds1 = new DataSet();
// ... fill the DataSet
// write the XML representation of DataSet ds1 to a file, with schema.
String fileName = @"c:\MyFile.xml";
ds1.WriteXml(fileName, XmlWriteMode.WriteSchema);
// load the XML file into DataSet ds2, with schema.
DataSet ds2 = new DataSet();
ds2.ReadXml(fileName, XmlReadMode.ReadSchema);
Note
The ReadXml( )
method can read the XML
representation of the DataSet
previously written
using the WriteXml( )
method into a
DataSet
.