« Return to Thread: "Invalid format" message using DataSet.ReadXML with a xs:dateTime column

"Invalid format" message using DataSet.ReadXML with a xs:dateTime column

by iguana :: Rate this Message:

Reply to Author | View in Thread

Hello,

I created a DataSet table with a DateTime column and saved it into a file using DataSet.WriteXML. Using the same code, the files created by .NET and MONO differ because, apparently, MONO saves DateTime values in a different way:

.NET:
<TestColumn>2008-06-06T07:07:00.009+02:00</TestColumn>
MONO:
<TestColumn>2008-06-06T07:07:00.0088888</TestColumn>

MONO saves the milliseconds more accurately but seems to be unaware of time zones. What's worse, however, is that when I create a file with .NET and then try to read it with MONO I get an "Invalid format" error message: MONO does not seem to be able to deal with the time zone information "+02:00" saved by .NET.

This is the VB code I use (having created a simple form with two buttons "cmdWriteXML" and "cmdReadXML"):


Imports System.Data
Public Class Form1
  Private TestFile As String = "C:\Test.xml"

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim MyDate As DateTime = CDate("06.06.2008 07:07").AddMilliseconds(8.8888)
    Dim TestTable As DataTable = New DataTable("TestTable")
    TestTable.Columns.Add("TestColumn", Type.GetType("System.DateTime"))
    Dim TestRow As DataRow = TestTable.NewRow
    TestRow("TestColumn") = MyDate
    TestTable.Rows.Add(TestRow)
    Dim TestDataSet As DataSet = New DataSet("TestDataSet")
    TestDataSet.Tables.Add(TestTable)
    TestDataSet.WriteXml(TestFile, XmlWriteMode.WriteSchema)
  End Sub

  Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Try
      Dim TestDataSet As DataSet = New DataSet()
      TestDataSet.ReadXml(TestFile, XmlReadMode.ReadSchema)
      MsgBox("Success")
    Catch ex As Exception
      MsgBox(ex.Message)
    End Try
  End Sub
End Class

Clicking both Button1 and Button2 in .NET produces "Success".
Clicking both Button1 and Button2 in MONO produces "Success".
Clicking Button1 in MONO and Button2 in .NET produces "Success."
Clicking Button1 in .NET and Button2 in MONO produces "Invalid format."


The file created by this code looks like this:

<?xml version="1.0" standalone="yes"?>
<TestDataSet>
  <xs:schema id="TestDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xs:element name="TestDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
      <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element name="TestTable">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="TestColumn" type="xs:dateTime" minOccurs="0" />
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:choice>
      </xs:complexType>
    </xs:element>
  </xs:schema>
  <TestTable>
    <TestColumn>   ***DIFFERENT VALUES SEE ABOVE***   </TestColumn>
  </TestTable>
</TestDataSet>


Is this a bug in MONO? Can it be fixed?

Regards
iguana

 « Return to Thread: "Invalid format" message using DataSet.ReadXML with a xs:dateTime column