By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,161 Members | 2,002 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,161 IT Pros & Developers. It's quick & easy.

load xml file containing header line

P: n/a
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.Read WithCollectTextToken()
+ 0x93 bytes
system.xml.dll!System.Xml.XmlValidatingReader.Read () + 0x1b bytes
system.xml.dll!System.Xml.XmlLoader.LoadCurrentNod e() + 0x9e bytes
system.xml.dll!System.Xml.XmlLoader.LoadDocSequenc e(System.Xml.XmlDocume
nt parentDoc) + 0x32 bytes
system.xml.dll!System.Xml.XmlLoader.Load(System.Xm l.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.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
* Atara <At***@DD.com> scripsit:
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?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2

P: n/a
The line should be:

<?xml version="1.0"?>

Note that there is no space before the final ?.
"Atara" <At***@DD.com> wrote in message
news:eQ****************@TK2MSFTNGP15.phx.gbl...
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.Read WithCollectTextToken()
+ 0x93 bytes
system.xml.dll!System.Xml.XmlValidatingReader.Read () + 0x1b bytes
system.xml.dll!System.Xml.XmlLoader.LoadCurrentNod e() + 0x9e bytes
system.xml.dll!System.Xml.XmlLoader.LoadDocSequenc e(System.Xml.XmlDocume
nt parentDoc) + 0x32 bytes
system.xml.dll!System.Xml.XmlLoader.Load(System.Xm l.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.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #3

P: n/a
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.