473,385 Members | 1,518 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,385 software developers and data experts.

Xml Validation - splitting good and bad elements

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());
....
Sep 8 '06 #1
2 1382
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
Sep 8 '06 #2
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?
"Hans Kesting" wrote:
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
Sep 11 '06 #3

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

Similar topics

0
by: C. M. Sperberg-McQueen | last post by:
wooks (wookiz@hotmail.com) wrote: > <?xml version='1.0'?> > <userlogin xmlns="urn:faster:userlogin" > xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'> > <login>mick</login> > ...
21
by: AnnMarie | last post by:
<script language="JavaScript" type="text/javascript"> <!-- function validate(theForm) { var validity = true; // assume valid if(frmComments.name.value=='' && validity == true) { alert('Your...
3
by: Skippytpe | last post by:
Does anyone have an idea why the form validation in the following page wouldn't be working? I had been using XHTML 1.0 transitional which allowed me to use the form attribute 'name.' I could then...
2
by: webbedfeet | last post by:
Hi I hope someone can help me. I have a client side form validation script which works perfectly in IE but clicking "Submit" in Mozilla does nothing - the form won't submit. Is there something I...
4
by: jedimasta | last post by:
Good evening all, I'm a relatively new to javascript, but I've been working with ColdFusion and PHP for years so I'm not necessarily ignorant, just stuck and frustrated. Using ColdFusion I'm...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
9
by: mstilli | last post by:
Hi, I am trying to use schema for server side validation using xerces to catch the validation errors. validating this XML: <Content4> <textarea13></textarea13>...
13
by: Andrew Falanga | last post by:
HI, Just a warning, I'm a javascript neophyte. I'm writing a function to validate the contents of a form on a web page I'm developing. Since I'm a neophyte, this function is quite simple at...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.