Xml Validation - splitting good and bad elements

G

Guest

Hi,
I'm using C# in VS.NET 2005. I have got the code working to validate an
entire XML file and raise events for validation errors and warnings (see
below). My question is how can I modify this code so that I end up with two
XML documents, one with the valid records and one with the rejected?
TIA.

....
fs = new FileStream(xmlFile, FileMode.Open);

XmlReaderSettings settings = new XmlReaderSettings();
settings.Schemas.Add("", schemaFile);
settings.ValidationType = ValidationType.Schema;
settings.ValidationEventHandler += new
ValidationEventHandler(ValidationEventHandler);

reader = XmlReader.Create(fs, settings);

while (reader.Read());
....
 
H

Hans Kesting

Hi,
I'm using C# in VS.NET 2005. I have got the code working to validate an
entire XML file and raise events for validation errors and warnings (see
below). My question is how can I modify this code so that I end up with two
XML documents, one with the valid records and one with the rejected?
TIA.

...
fs = new FileStream(xmlFile, FileMode.Open);

XmlReaderSettings settings = new XmlReaderSettings();
settings.Schemas.Add("", schemaFile);
settings.ValidationType = ValidationType.Schema;
settings.ValidationEventHandler += new
ValidationEventHandler(ValidationEventHandler);

reader = XmlReader.Create(fs, settings);

while (reader.Read());
...

I don't think it is possible to define "valid" and "invalid" records.
If some end-tag is missing, the validation will detect a mismatch. But
it will not know what went wrong:
- type-error in starttag
- type-error in endtag
- endtag missing
- endtag extra
What would be the "invalid records" in this case?

Hans Kesting
 
G

Guest

Thanks Hans, good point.

Given say that the document structure is valid shouldn't there be a way to
identify which elements conform to certain data constraints defined in the
XSD?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top