What started as a gentle little stroll in paths I don't usually walk has me entangled in briars! I cannot for the life of me work out why ...
... which results in
Always gives me this ...
There is an error in XML document (3, 4).
... on line 13 of the code above.
I have also tried using a Dataset including the table and serializing the Dataset with exactly the same result. How can there be an error in the XML if the XML was written by the same Serializer that's now reading it?
vb.net Code:
Public Class Form1 Dim dt As New DataTable("Stuff") Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load dt.Columns.Add("Forename") dt.Columns.Add("Surname") dt.Rows.Add({"Esmeralda", "Finklepopper"}) dt.Rows.Add({"Algernon", "Strumple"}) Else Dim sr As New IO.StreamReader("C:\dtable.xml") Dim ds As New Xml.Serialization.XmlSerializer(dt.GetType) dt = CType(ds.Deserialize(sr), DataTable) sr.Close() End If DataGridView1.DataSource = dt End Sub Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim sw As New IO.StreamWriter("C:\dtable.xml") Dim s As New Xml.Serialization.XmlSerializer(dt.GetType) s.Serialize(sw, dt) sw.Close() End Sub End Class
... which results in
Code Code:
<?xml version="1.0" encoding="utf-8"?> <DataTable> <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Stuff" msdata:UseCurrentLocale="true"> <xs:complexType> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element name="Stuff"> <xs:complexType> <xs:sequence> <xs:element name="Forename" type="xs:string" minOccurs="0" /> <xs:element name="Surname" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> </xs:element> </xs:schema> <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"> <DocumentElement> <Stuff diffgr:id="Stuff1" msdata:rowOrder="0" diffgr:hasChanges="inserted"> <Forename>Esmeralda</Forename> <Surname>Finklepopper</Surname> </Stuff> <Stuff diffgr:id="Stuff2" msdata:rowOrder="1" diffgr:hasChanges="inserted"> <Forename>Algernon</Forename> <Surname>Strumple</Surname> </Stuff> </DocumentElement> </diffgr:diffgram> </DataTable>
Always gives me this ...
Quote:
There is an error in XML document (3, 4).
I have also tried using a Dataset including the table and serializing the Dataset with exactly the same result. How can there be an error in the XML if the XML was written by the same Serializer that's now reading it?