[Mono-bugs] [Bug 52581][Nor] New - System.Data.DataSet.ReadXml and System.Data.DataSet.WriteXml don't properly serialize to XML with inline schema when XmlReadMode.ReadSchema/XmlWriteMode.WriteSchema is specified
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Sat, 3 Jan 2004 16:38:48 -0500 (EST)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by jmozelesky@netcarrier.com.
http://bugzilla.ximian.com/show_bug.cgi?id=52581
--- shadow/52581 2004-01-03 16:38:48.000000000 -0500
+++ shadow/52581.tmp.19625 2004-01-03 16:38:48.000000000 -0500
@@ -0,0 +1,138 @@
+Bug#: 52581
+Product: Mono/Class Libraries
+Version: unspecified
+OS: Fedora 1.0
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: System.Data
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: jmozelesky@netcarrier.com
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: System.Data.DataSet.ReadXml and System.Data.DataSet.WriteXml don't properly serialize to XML with inline schema when XmlReadMode.ReadSchema/XmlWriteMode.WriteSchema is specified
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+When serializing a DataSet to XML using System.Data.DataSet.WriteXml(
+fileName, XmlWriteMode.WriteSchema ) to inline the xsd, it only writes out
+the xsd, not the subsequent XML data.
+
+When reading a DataSet from XML using System.Data.DataSet.ReadXml(
+fileName, XmlReadMode.ReadSchema ), it then throws an exception because
+there is no data after the schema.
+
+Steps to reproduce the problem:
+Use this test case:
+
+// BEGIN TEST CASE
+using System;
+using System.Data;
+
+class TestDataSetXml {
+
+ public static void Main(string[] args) {
+ string fileName = "testDataSet.xml";
+ DataSet ds = new DataSet("ObjectWarehouseSchema");
+ DataTable dtTypes = new DataTable("ObjectSchemaTypes");
+
+
+ dtTypes.Columns.Add( new DataColumn("TypeName", typeof(string)) );
+
+ dtTypes.Columns.Add( new DataColumn("TableName", typeof(string)) );
+ dtTypes.Columns.Add( new DataColumn("TestNumericField", typeof(int)) );
+
+ DataRow drType = dtTypes.NewRow();
+
+
+
+ drType["TypeName"] = "Order";
+
+ drType["TableName"] = "orders";
+ drType["TestNumericField"] = 1;
+
+ dtTypes.Rows.Add( drType );
+
+ ds.Tables.Add( dtTypes );
+ Console.WriteLine( "Writing DataSet to file: {0} with inline schema.",
+fileName );
+
+ ds.WriteXml( fileName, XmlWriteMode.WriteSchema );
+
+ Console.WriteLine( "Attempting to load DataSet from file: {0} with inline
+schema.", fileName );
+ ds = new DataSet("ObjectWarehouseSchema");
+ ds.ReadXml( fileName, XmlReadMode.ReadSchema );
+ dtTypes = ds.Tables["ObjectSchemaTypes"];
+
+ Console.WriteLine( "Schema read. The following XML data was found: ");
+ Console.WriteLine( ds.GetXml() );
+ }
+}
+// END TEST CASE
+
+Actual Results:
+Writes XML Schema of the dataset to the specified file. Below is exactly
+what the test case writes out:
+
+<ObjectWarehouseSchema>
+ <xsd:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+attributeFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+ <xs:element name="ObjectWarehouseSchema" msdata:IsDataSet="true"
+msdata:Locale="" xmlns:xs="http://www.w3.org/2001/XMLSchema"
+xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:complexType xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+ <xs:choice maxOccurs="unbounded"
+xmlns:xs="http://www.w3.org/2001/XMLSchema">
+ <xsd:element name="ObjectSchemaTypes"
+xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+ <xs:complexType xmlns:xs="http://www.w3.org/2001/XMLSchema">
+ <xsd:sequence xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+ <xs:element minOccurs="0" type="xsd:string" name="TypeName"
+xmlns:xs="http://www.w3.org/2001/XMLSchema" />
+ <xsd:element minOccurs="0" type="xsd:string"
+name="TableName" />
+ <xsd:element minOccurs="0" type="xsd:int"
+name="TestNumericField" />
+ </xsd:sequence>
+ </xs:complexType>
+ </xsd:element>
+ </xs:choice>
+ </xsd:complexType>
+ </xs:element>
+ </xsd:schema>
+
+Reading the dataset in produces the following exception:
+Unhandled Exception: System.Xml.XmlException: unexpected end of file.
+Current depth is 1
+in <0x001ee> System.Xml.XmlTextReader:ReadContent ()
+in <0x001a0> System.Xml.XmlTextReader:Read ()
+in <0x00209> System.Xml.Schema.XmlSchema:Read
+(System.Xml.XmlReader,System.Xml.Schema.ValidationEventHandler)
+in <0x00073> System.Data.XmlSchemaMapper:Read (System.Xml.XmlReader)
+in <0x00043> System.Data.DataSet:ReadXmlSchema (System.Xml.XmlReader)
+in <0x000aa> System.Data.XmlDataLoader:ReadModeSchema
+(System.Xml.XmlReader,bool)
+in <0x00060> System.Data.XmlDataLoader:LoadData
+(System.Xml.XmlReader,System.Data.XmlReadMode)
+in <0x000a0> System.Data.DataSet:ReadXml
+(System.Xml.XmlReader,System.Data.XmlReadMode)
+in <0x0003e> System.Data.DataSet:ReadXml (string,System.Data.XmlReadMode)
+in <0x00269> .TestDataSetXml:Main (string[])
+
+
+Expected Results:
+Writes XML Schema of the dataset as well as the actual data in XML form to
+the specified file.
+
+How often does this happen?
+Always.
+
+Additional Information:
+Workaround: Don't inline the schema. Use System.Data.DataSet.WriteXml(
+fileName ) and System.Data.DataSet.ReadXml( fileName ) instead.