Re: XML Cleaner
From: Daniel Cazzulino [MVP XML] (kzuAT_at_NOaspnet2SPAMPLZ.com)
Date: 04/20/04
- Next message: Mickey Williams: "Re: Problems with Deserialization.. There is an error in XML document (1, 2)."
- Previous message: Daniel Cazzulino [MVP XML]: "Re: Xsl Transform in .NET is Really Slow."
- In reply to: Matthew Wieder: "XML Cleaner"
- Next in thread: Matthew Wieder: "Re: XML Cleaner"
- Reply: Matthew Wieder: "Re: XML Cleaner"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 20 Apr 2004 19:38:43 -0300
First, you shouldn't let the validating reader throw exceptions, but call a
delegate you provide for the ValidationEventHandler.
Even so, as I explained in
http://weblogs.asp.net/cazzu/archive/2004/03/24/95588.aspx, you can't just
call sender.Skip() because due to a bug in v1.x, it's not set to the reader
raising the event.
Therefore, you will need to keep a reference to the reader at the class
level in a field, and in the validation handler method, skip the current
node:
private void OnValidationError(object sender, ValidationEventArgs e)
{
if (e.Severity = XmlSeverityType.Error)
{
// Accumulate error, set flag.
_thereader.Skip();
}
}
That should do the job.
-- Daniel Cazzulino [MVP XML] Clarius Consulting SA http://weblogs.asp.net/cazzu http://aspnet2.com "Matthew Wieder" <Development@SatoriGroupInc.com> wrote in message news:Oh#zDjuJEHA.1224@TK2MSFTNGP11.phx.gbl... > I was hoping that someone could point me in the right direction. I'm > looking to develop a tool that will run an XML file against an XSD > schema and if a node doesn't conform to the schema, remove that node > from the xml (or output a new xml without that node) and continue > through the whole document until it is "Clean" (valid). > The code to validate against the schema is strightforward, but how do I > use the exceptions thrown by the XmlValidatingReader to clean the XML file? > thanks! > --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.655 / Virus Database: 420 - Release Date: 08/04/2004
- Next message: Mickey Williams: "Re: Problems with Deserialization.. There is an error in XML document (1, 2)."
- Previous message: Daniel Cazzulino [MVP XML]: "Re: Xsl Transform in .NET is Really Slow."
- In reply to: Matthew Wieder: "XML Cleaner"
- Next in thread: Matthew Wieder: "Re: XML Cleaner"
- Reply: Matthew Wieder: "Re: XML Cleaner"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|