load xml file containing header line

A

Atara

I use the following code to load xml file:

Dim srcXml As String = pathDataFiles & "test.xml"
Dim XmlDoc As New Xml.XmlDocument
XmlDoc.Load(srcXml)

If my xml file starts with the line -

<?xml version="1.0" ?>

I get -
An unhandled exception of type
'System.Xml.XmlException' occurred in system.xml.dll
Additional information: System error.

Call Stack:
system.xml.dll!System.Xml.XmlTextReader.ParseTag() + 0x96b bytes
system.xml.dll!System.Xml.XmlTextReader.ParseRoot() + 0xed bytes
system.xml.dll!System.Xml.XmlTextReader.Read() + 0x80 bytes
system.xml.dll!System.Xml.XmlValidatingReader.ReadWithCollectTextToken()
+ 0x93 bytes
system.xml.dll!System.Xml.XmlValidatingReader.Read() + 0x1b bytes
system.xml.dll!System.Xml.XmlLoader.LoadCurrentNode() + 0x9e bytes
system.xml.dll!System.Xml.XmlLoader.LoadDocSequence(System.Xml.XmlDocume
nt parentDoc) + 0x32 bytes
system.xml.dll!System.Xml.XmlLoader.Load(System.Xml.XmlDocument doc,
System.Xml.XmlReader reader, bool preserveWhitespace) + 0x6a bytes
system.xml.dll!System.Xml.XmlDocument.Load(System.Xml.XmlReader reader)
+ 0x49 bytes
system.xml.dll!System.Xml.XmlDocument.Load(string filename) + 0x51 bytes
myPrj.exe!mySln...myFunction(...) + 0xa0 bytes

If I comment-out these header line,
everything seems to work fine.

Question: How can I load a file containing this xml header line, without
getting any exceptions?

Thanks.

Atara.
 
S

Stephany Young

The line should be:

<?xml version="1.0"?>

Note that there is no space before the final ?.
 
H

Herfried K. Wagner [MVP]

* Atara said:
I use the following code to load xml file:

Dim srcXml As String = pathDataFiles & "test.xml"
Dim XmlDoc As New Xml.XmlDocument
XmlDoc.Load(srcXml)

If my xml file starts with the line -

<?xml version="1.0" ?>

I get -
An unhandled exception of type
'System.Xml.XmlException' occurred in system.xml.dll
Additional information: System error.

I am not able to repro that. What encoding do you use to store the
file?
 
A

Atara

I think I found it, if the decleration does not start on the first-line,
first character, I get this exception.

conclusion: do not add blank lines before the xml declaration line...

Thanks anyway.

Atara
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top