Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

Custom error code when XSD validation fails?

Question posted by: Artie (Guest) on June 27th, 2008 07:20 PM
Hi,

Is there any way to tell an XSD Schema that you want custom error
codes for particular validation failures in an XML document?

To show what I mean, here's an example:

XSD excerpt:

<xs:element name = "EmployeeID">
<xs:simpleType>
<xs:restriction base = "xs:string" >
<xs:length value = "3"/>
<xs:pattern value = "[0-9]{3}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

XML excerpt:

<EmployeeID>1234</EmployeeID>

When the XML fails to validate against its XSD element, I want, say,
error code 1000 to be returned from the validator for further parsing
in my C# code - can this be done easily?

(I'm thinking along the lines of having an element like
<xs:customErrorCode = 1000along side each restriction.)

Any help very much appreciated

Artie
Martin Honnen's Avatar
Martin Honnen
Guest
n/a Posts
June 27th, 2008
07:20 PM
#2

Re: Custom error code when XSD validation fails?
Artie wrote:
Quote:
When the XML fails to validate against its XSD element, I want, say,
error code 1000 to be returned from the validator for further parsing
in my C# code - can this be done easily?
>
(I'm thinking along the lines of having an element like
<xs:customErrorCode = 1000along side each restriction.)
>
Any help very much appreciated


There is no such element as xs:customErrorCode but the schema language
allows for custom attributes in a different namespace than the schema
namespace (http://www.w3.org/2001/XMLSchema). And there are annotations
allowed (http://www.w3.org/TR/xmlschema-1/#cAnnotations) so that a
schema can have additional information, both for human readers and for
automated processing. The schema object model (SOM) in the .NET
framework allows you to access the attributes
(http://msdn2.microsoft.com/en-us/li...tr ibutes.aspx)
and the annotations
(http://msdn2.microsoft.com/en-us/li...notation.as px)

So you can put such information into your schema(s) and then extract
them when processing the schema.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

 
Not the answer you were looking for? Post your question . . .
189,173 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors