root element is missing
Posted on 2011-10-31
I'm trying to read a DataSet from an SQL connection and then write it to an XML file and then subsequenltly reload it. These are the functions I'm using:
Private Sub WriteXmlToFile(ByVal thisDataSet As DataSet)
If thisDataSet Is Nothing Then
' Create a file name to write to.
Dim filename As String = "c:\myXmlDoc.xml"
' Create the FileStream to write with.
Dim myFileStream As New System.IO.FileStream _
' Create an XmlTextWriter with the fileStream.
Dim myXmlWriter As New System.Xml.XmlTextWriter _
' Write to the file with the WriteXml method.
Private Sub ReadXmlToFile(ByVal xmlFilename As String, ByVal newDataSet As DataSet)
' Read the XML document back in.
' Create new FileStream to read schema with.
Dim fsReadXml As New System.IO.FileStream _
' Create an XmlTextReader to read the file.
Dim myXmlReader As New System.Xml.XmlTextReader(fsReadXml)
' Read the XML document into the DataSet.
' Close the XmlTextReader
I am calling the code as follows:
Dim dataSet1 As New DataSet
Catch ex As Exception
The code throws an exception stating that "root element is missing".
Can anybody tell me what is wrong?
This is the XML that is created during the write statement: