Solved

How can I raise a custom error message in an XSD?

Posted on 2006-06-29
7
757 Views
Last Modified: 2012-06-21
I have an XSD document which validates my xml files. I want to display a custom error message when one of the criteria in the XSD definition is not met by the xml file. For example, I want to validate a node which contains  a date value. If that date is not valid according to the schema definition, I want to raise custom error message saying the date is not valid.

Is it possible to raise custom error messages in xsd? If yes, how can we do that?

Looking forward to your response.

Tx
0
Comment
Question by:chaleastale
  • 3
  • 2
7 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 17016066
Hi chaleastale,

there are various ways to do that.

most elegant seems to me to use a parser class in any programming language you would like
(just wrap the parser)
and catch the error raised by the parser and raise an exception with a new message

you could also use Schematron to validate and choose your own messages

Cheers!
0
 

Author Comment

by:chaleastale
ID: 17016929
I appreciate your response. Could you please send me some sample code for doing that? I haven't ever done raising a custom error message in xsd.

Thank you.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 17016981
well, what programming language would you use to call the parser?
0
 

Author Comment

by:chaleastale
ID: 17017085
I am using c#.

Thanks again
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 250 total points
ID: 17026156
chaleastale,
> I am using c#.

Here is an example on how to validate XML with XSD schema in C#

http://support.microsoft.com/default.aspx?scid=kb;en-us;318504

That is what you can use to validate your XML, using C#

somewhere down there you have a catch
            catch(XmlSchemaException XmlSchExp)
            {
                Console.WriteLine(XmlSchExp.Message);
            }

this one just writes the exception message to the console
Now in your program, you can check what that message is
and write an alternative to the console...

that is all there is to it

cheers
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question