Page 1 of 1

Restricting an Elements value

Posted: Fri Mar 30, 2012 1:39 pm
by glawson
I am trying to restriction a value that is allowed to be captured for a particular feature. My current schema has the following

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml">

<!-- The following simplyType feature has been added to constrain the allowed value range supplied
VARCHAR2 (38 Byte) i.e. Programming: GUID (including brackets using parentheses)) -->
<xs:simpleType name="ReferenceGUID">
<xs:restriction base="xs:token">
<xs:pattern value="\{[A-Z0-9]{8}(\-[A-Z0-9]{4}){3}\-[A-Z0-9]{12}\}"/>
</xs:restriction>
</xs:simpleType>

</xs:schema>


Validating against the following examples:

{ABDD8E39-0BB7-407F-9BAA-CF300A7AF661}
{EB42708E-44764-9F98-0CB6E5A6FAFB}
{A699AB0A-26-8C4A-E040-A40A262C4E4E}
{00000000-0000-0000-0000-000000000000}

It will successfully 'fail' the second and third example, but pass the fourth! What i trying to validate is that the value range captured must be alphanumeric.

Re: Restricting an Elements value

Posted: Tue Apr 03, 2012 2:43 pm
by Costin
Hello,

All the values in the examples you specified are alphanumeric - including the fourth one.
The validation works OK and the behaviour is completely normal.

From the three examples you specified (2,3 and 4), only the fourth one is in accordance with the accepted pattern you set in the restriction.
That is because, regarding the character numbers, your pattern value should be like : 8 - 4 - 4 - 4 - 12. The 2nd and the 3rd examples do not follow the characters number restriction in the pattern (as they are: 8-5-4-12 and 8-2-4-4-12).

Do you want the validation to also "fail" for the 4th example ?

Regards,
Costin.

Re: Restricting an Elements value

Posted: Tue Apr 03, 2012 3:04 pm
by glawson
Hello Colin

The only example i want to pass would be the first one i.e. with the format '{8-4-4-4-12}' (e.g. {BCB385F9-2A19-5ADC-E040-A40A272C6A8A}). Whilst i am aware that technically the 4th one does follow that rule, and is again technically alphanumeric. What i am trying to trap is when only zero's <0> are used in all none '{' or '-' positions, instead of a mixture of letters (ideally in the range 'A-F') and numbers '0-9'.

Glawson

Re: Restricting an Elements value

Posted: Tue Apr 03, 2012 4:51 pm
by adrian
Hi,

To easily exclude that particular value(all zeros), you would need a regular expression with negative lookahead. e.g.

Code: Select all

(?!\{00000000\-0000\-0000\-0000\-000000000000\})(\{[A-Z0-9]{8}(\-[A-Z0-9]{4}){3}\-[A-Z0-9]{12}\})
Unfortunately XML Schema 1.0 does not support negative lookahead in the regular expression patterns, which makes an expression that does this very tedious to write. Actually, considering the length of your string, I consider the alternative impractical.

There are a few articles on StackOverflow that exemplify how this can be done, but I don't see these as a proper solution in your case:
http://stackoverflow.com/questions/8127 ... xml-schema
http://stackoverflow.com/questions/9988 ... ema-flavor


Are you limited to XML Schema, or are you allowed to use other types of schema(e.g. XML Schema + Schematron or embedded Schematron) to accomplish this?

Regards,
Adrian