Solved

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

Posted on 2006-06-29
7
808 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 

734 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