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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error "XmlException was unhandled"

Status
Not open for further replies.

IlyaRabyy

Programmer
Nov 9, 2010
571
US
Colleagues,

Picture worth 1000 words, therefore:
20200304_Unhandled_XmlException_cvzwjr.jpg

What am I doing wrong?

TIA!

Regards,

Ilya
 
Because you don't have a legitimate XML file

You earlier 'test' for legitimacy is no such thing, I am afraid. Let the XMLReader do the validation for you ...
 
strongm: "Let the XMLReader do the validation for you"

How? Try-Catch and analyze the error message?
Please advise.
TIA!

Regards,

Ilya
 
>How? Try-Catch and analyze the error message?

Yep, that would be one way.

You can even validate against a schema, if you had one (one of the things you can use XMLReaderSettings for).

But you never actually set any XMLreader settings, which is beginning to make me think that much of this looks like cut'n'pasted code from multiple sources without really knowing what the code is doing

You might want to examine the documentation for XMLReaderSettings and fore XML schemas
 
Actually, this "one way" (Try-Catch) did work!

And you have guessed right: this test POStart.XML (that I "inherited" from my predecessor) was a kind of header (or template of a sorts) for a real test XML. And it has no closing tags for the 1st several levels... coz there's POEnd.XML with all these closing tags. And the test data is supposed to be "sandwiched" between these former two.

This my predecessor read it with System.IO.File.OpenText()/While Peek()/ReadLine()/Close(), and I am trying to read it with XmlReader... (Doh!)

"You can always count on Americans to do the right thing - after they've tried everything else." (Sir W. Churchill, I presume? ;-) )
Apparently, I haven't tried everything else... yet! [lol]

Regards,

Ilya
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top