Solved

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

Posted on 2006-06-29
7
734 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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. 
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now