Reads XML schema and data into the System.Data.DataSet using the specified System.Xml.XmlReader.
- reader
- The System.Xml.XmlReader from which to read.
The XmlReadMode used to read the data.
The DataSet.ReadXml(System.Xml.XmlReader) method provides a way to read either data only, or both data and schema into a System.Data.DataSet from an XML document, whereas the DataSet.ReadXmlSchema(System.Xml.XmlReader) 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.
Note that the same is true for the DataSet.WriteXml(System.IO.Stream) and DataSet.WriteXmlSchema(System.IO.Stream) 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.
An InvalidOperationException will be thrown if a column type in the DataRow being read from or written to implements System.Dynamic.IDynamicMetaObjectProvider and does not implement System.Xml.Serialization.IXmlSerializable.
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.
The DataSet does not associate an XML element with 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 System.Data.DataSet includes a targetNamespace, data may not be read, and you may encounter exceptions when calling DataSet.ReadXml(System.Xml.XmlReader) to load the System.Data.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.
Example
<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>
System.Xml.XmlTextReader inherits from System.Xml.XmlReader.
If the schema for your System.Data.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 System.Data.DataSet with DataSet.ReadXml(System.Xml.XmlReader) by specifying XmlReadMode.ReadSchema. This exception does not occur if you are using .NET Framework version 1.0.