473,394 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

XmlValidatingReader: continue parsing after XmlException

When attempting to validate an XML file, If the file is valid, it
validates correctly, and it will catch most ValidationEvents without
problem. However, I keep getting the following Exception:
System.Xml.XmlException: The 'RDaaaa' start tag on line '4' doesn't
match the end tag of 'RD' in file 'file:///C:/Work/WIMAR
XML/WI_M_1.xml'. Line 4, position 475.
at System.Xml.XmlTextReader.ParseTag()
at System.Xml.XmlTextReader.ParseBeginTagExpandCharEn tities()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlValidatingReader.ReadWithCollectText Token()
at System.Xml.XmlValidatingReader.Read()
at XMLValidator.XMLEvaluator.Evaluate(String configPath) in
c:\documents and settings\gwalker\my documents\visual studio
projects\xmlvalidator\xmlevaluator.cs:line 43

Well, this technically is doing what it's supposed to be doing, but I'd
rather have XmlExceptions fired as Events rather than throwing
exceptions. With a try-finally block, I want to easily be able to get
back into reading the XML file after an exception like this. (I am sort
of a newbie in all this, so apologies if this is a really really simple
question.)

I know that my XML and schema are valid. I introduced the error for
testing purposes.
I'm using the following example code from MSDN:
public void Evaluate(string configPath)
{
/**
* if file is okay, return 1
* if file is not okay, return error string
*/
XmlTextReader evaluated = new XmlTextReader(configPath);
XmlValidatingReader val = new XmlValidatingReader(evaluated);
try
{
Console.WriteLine("Validating XML file ");

// Set the validation event handler
val.ValidationEventHandler += new
ValidationEventHandler(this.ValidationEventHandle) ;

// Read XML data
while (val.Read()){}

Console.WriteLine ("Validation finished. Validation {0}",
(m_success==true ? "successful" : "failed"));
}
finally
{
//Close the reader.
if (val != null)
val.Close();
}
}// end of Evaluate method

private void ValidationEventHandle (object sender, ValidationEventArgs
args)
{
m_success = false;
Console.WriteLine("Validation error: " + args.Message );
}
Nov 12 '05 #1
1 2616
>Well, this technically is doing what it's supposed to be doing, but I'd
rather have XmlExceptions fired as Events rather than throwing
exceptions. With a try-finally block, I want to easily be able to get
back into reading the XML file after an exception like this. (I am sort
of a newbie in all this, so apologies if this is a really really simple
question.)


The Validation event handler only catches violations of the schema in the
XML document. But the Xml Document need to be well formed to begin with.
Parsing can NOT continue after encountering a well formedness errors.
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nick Finch | last post by:
Hi, I wonder if anyone else has come across this. The code below is very simple however I cannot get the ValidationHandler to be raised. I am testing with xml that I know will not validate...
2
by: matthew.schneider | last post by:
I have a defined XML Schema, and XML documents containing data that I validate against it. Periodically, I will have a data document that will contain extra elements that are not part of my schema....
5
by: Geoff | last post by:
I am using an XMLValidatingReader to validate an XML file received via a web service. I want to verify that the incoming file matches the XML schema. When testing the validation routine, the...
1
by: rampm2007 | last post by:
Hi, I am using the XmlTextReader along XmlValidatingReader for parsing the XML file. Becuase of the foreign characters sometimes I get the "There is an invalid character in the given encoding"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.