Page 1 of 1

length of match-Attribute

Posted: Fri Dec 02, 2005 11:50 pm
by muewi
Hi,

I need to write an extremely long regular expression in <xs:pattern value=" ..".
How long can it be? Is there a way to split the regular expression up?

Thank you,
Frank

Posted: Mon Dec 05, 2005 5:28 pm
by sorin_ristache
Hello,

The XML Schema specification does not set a maximum length for an attribute value. You can use a pattern of 100,000 characters as a value of the xs:pattern/@value attribute but for readability you should split the pattern into subpatterns, define separate types for each subpattern and chain the types to apply all the patterns to the same value. For example the content model of the element a defined by the following schema allows only strings of 1 to 10 lowercase letters followed by 0 to 5 uppercase letters:

Code: Select all

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="lowercase">
<xs:restriction base="xs:string">
<xs:pattern value="\p{Ll}{1,10}.{0,5}"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="uppercaseAndLowercase">
<xs:restriction base="lowercase">
<xs:pattern value=".{1,10}\p{Lu}{0,5}"/>
</xs:restriction>
</xs:simpleType>

<xs:element name="a" type="uppercaseAndLowercase"/>
</xs:schema>
Regards,
Sorin