I am trying to open an XML... the file was written by VB.Net using the dataset.WriteXML method
When I use the ReadXML method to open it, I get the message: The data at the root level is invalid. Line 1, Position 1.
I have open the file in IE with out any problems.
I am not using a schema file... please let me know if you think this is why.
Comments
~rlc
:
: ~rlc
:
dim ds as new dataset
dim fs as IO.StreamReader("FileName.XML")
dim xr as XML.XmlTextReader(fs)
ds.ReadXml(xr)
I think the problem is you are not using "NEW" the create instances of the test reader and stream. If you just do...
[code]ds.readxml()[/code]
It will work but you may lose some of the formatting.. I am not sure the exact difference. I have a function that loads tables in a DB during install using the reader method I will paste a relvant snip below...
~rlc
EDIT: P.S. this method assumes the XML file has the schema
[code]
' load each xml file into the database
Try
Dim lSqlConnection As SqlClient.SqlConnection = New SqlClient.SqlConnection(m_ConnectString)
Dim lCommand As SqlClient.SqlCommand
Dim lBuilder As SqlClient.SqlCommandBuilder
Dim lDataAdapter As SqlClient.SqlDataAdapter
Dim lDataSet As DataSet
Dim lCurrFileName As String
Dim lCurrTableName As String
Dim lXmlReader As Xml.XmlTextReader
For Each lCurrFileName In Directory.GetFiles(lXmlPath, "*.xml")
lCurrTableName = Path.GetFileNameWithoutExtension(lCurrFileName)
If Not m_IsUpdate OrElse Array.IndexOf(m_UpdateData, lCurrTableName) <> -1 Then
' do this table
WriteEvent("Loading data from " & lCurrFileName)
lCommand = New SqlClient.SqlCommand("SELECT * FROM [" & lCurrTableName & "]", lSqlConnection)
lDataAdapter = New SqlClient.SqlDataAdapter(lCommand)
lBuilder = New SqlClient.SqlCommandBuilder(lDataAdapter)
lDataSet = New DataSet(lCurrTableName)
lXmlReader = New Xml.XmlTextReader(lCurrFileName)
lDataSet.ReadXml(lXmlReader, XmlReadMode.ReadSchema)
lDataAdapter.Update(lDataSet)
lXmlReader.Close()
End If
Next
lSqlConnection.Close()
Catch ex As SqlClient.SqlException
WriteEvent("Error inserting data: " & ex.Message)
End Try
[/code]
: : I have used the DS function with the Schemea and without. What overload are you using for the ReadXML function?
: :
: : ~rlc
: :
: dim ds as new dataset
: dim fs as IO.StreamReader("FileName.XML")
: dim xr as XML.XmlTextReader(fs)
: ds.ReadXml(xr)
:
:
:
: I think the problem is you are not using "NEW" the create instances of the test reader and stream. If you just do...
: [code]ds.readxml()[/code]
I was using the "new" instance on the declaration... sorry I didn't include that in my previous message... but the above worked perfect, and is a much simpler method than having to use my own file stream and textreader... thanks for the help
I will look closer at you code as it looks like something I may need...