VB.Net XML Exception Opening document. Data at the root level is invalid. Line 1, position 1.

I'm new to XML and looking to pull the data from an XML document and put it into a SQL database.

When I try and open the document, i get an XMLException: {"Data at the root level is invalid. Line 1, position 1."}

The first line of the XML document I'm trying to read is:
  <?xml version="1.0" encoding="UTF-8" ?>

Because I'm new to XML, I'm not sure why this would be an issue.  Deleting lines down to the actual data still gives the same error (Hey, it was worth a try!)

I can open the file with an XML reader (if ProhibitDTD is set to false), but then parsing through the data seems to be a chore.

Any suggestions?  Any and all advice would be much appreciated!  Thanks in advance...
Who is Participating?
PaulHewsConnect With a Mentor Commented:

There's your problem... Use

genehayesAuthor Commented:
Ok, realized more info on this might be helpful...  Sorry!

I'm using VB.Net 2005 and trying to open the XML with:

       Dim reader As New Xml.XmlDataDocument

Using XMLDocument doesnt work either.  Same error message.
There should not be any space before the declaration tag.

If you are using XMLDocument, use Load and not LoadXML to load an URL or file.
genehayesAuthor Commented:
Thanks!  Seems so simple, but I wasn't getting it.

Stay tuned, probably more XML questions coming!

All Courses

From novice to tech pro — start learning today.