Re: XML Cleaner

From: Daniel Cazzulino [MVP XML] (kzuAT_at_NOaspnet2SPAMPLZ.com)
Date: 04/20/04


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


Relevant Pages

  • RE: Web service constants or default values
    ... The schema language does allow one to define default values ... reader fill in the defaults for them. ... you can pass the XML as ... the altered XML stream on to the default serializer. ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: Validating XML file against an XSD schema
    ... It's not necessary to validate an XML document against a schema ... Reader (which you can wrap around a number of sources: ...
    (microsoft.public.dotnet.xml)
  • Re: Alternative to Remoting?
    ... > you use WS with your custom objects without any problem? ... Just want to have a hash table to store temporary objects ... >> taking and dishing out XML. ... >> reader doesn't have a lot of properties, but you could do the same with ...
    (microsoft.public.dotnet.framework.compactframework)
  • XML->sexpr ideas [was Re: Name for the set of characters legal in identifiers]
    ... >>recognized by the reader as special characters. ... to parse some useful metadata out of an XML dtd. ... exchange with a FIX protocol interface. ...
    (comp.lang.lisp)
  • Re: Constellations
    ... You want a set of dirs, with exceptions, and exceptions to the ... only XML. ... expressed using XML or that expressing the list using a combination of ...
    (comp.lang.java.programmer)