Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-06-29
7
Medium Priority
?
918 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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
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, …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

688 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