Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading an xml file into an xml document

Status
Not open for further replies.

JABOSL

Programmer
Jan 25, 2006
35
Can someone help me figure out why this isn't working? I always get the exception "The data at the root level is invalid. Line 1, position 1." on the doc.loadxml line.

Code:
        Dim doc As Xml.XmlDocument = New Xml.XmlDocument
        Dim reader As New Xml.XmlTextReader("c:\test.xml")
        
        Try
            doc.LoadXml(reader.Read)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

Here's what I'm reading. I've tried it with out the first (?xml...) line too but it still gives me the error.

<?xml version="1.0" encoding="UTF-8"?>
<request>
<sequence_number>000002</sequence_number>
<account_number>103363463355</account_number>
<response_fields>
<reply_code>201</reply_code>
</response_fields>
</request>
 
I am not sure:

<response_fields>
<reply_code>201</reply_code>
</response_fields>

A single XML element can contain either other elements or data, but NOT both.


 
No need to use reader either as you might have noticed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top