length of match-Attribute

This should cover W3C XML Schema, Relax NG and DTD related problems.
muewi
Posts: 26
Joined: Wed Aug 24, 2005 10:47 am

length of match-Attribute

Post by muewi » Fri Dec 02, 2005 11:50 pm

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

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache » Mon Dec 05, 2005 5:28 pm

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

Post Reply