VB.NET

Moderators: seancampbell
Number of threads: 4020
Number of posts: 10026

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
XML file error Posted by digitalgeek on 13 Sept 2005 at 3:41 AM
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.

Report
Re: XML file error Posted by rlc on 13 Sept 2005 at 6:05 AM
I have used the DS function with the Schemea and without. What overload are you using for the ReadXML function?

~rlc
Report
Re: XML file error Posted by digitalgeek on 13 Sept 2005 at 6:38 PM
: 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)


Report
Re: XML file error Posted by rlc on 13 Sept 2005 at 6:50 PM
This message was edited by rlc at 2005-9-13 18:51:28

I think the problem is you are not using "NEW" the create instances of the test reader and stream. If you just do...
ds.readxml(<filename>)

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

        ' 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



: : 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)
:
:
:


Report
Re: XML file error Posted by digitalgeek on 14 Sept 2005 at 5:23 AM
: This message was edited by rlc at 2005-9-13 18:51:28

: I think the problem is you are not using "NEW" the create instances of the test reader and stream. If you just do...
:
ds.readxml(<filename>)



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...





 

Recent Jobs