XML technologies / XML Schema / XML Schema element reference / xs:pattern

(Excerpt from “XML Schema” by Eric van der Vlist)

Facet specifying a condition through a regular expression.

<xs:pattern
    id = xs:ID
    value = anySimpleType
    {beliebige Attribute mit einem Nicht-Schema-Namensraum}
    >
    Content: (xs:annotation?)
</xs:pattern>

May occur within: xs:restriction (simple type), xs:restriction (simple content)

May be used as a facet for: xs:anyURI, xs:base64Binary, xs:boolean, xs:byte, xs:date, xs:dateTime, xs:decimal, xs:double, xs:duration, xs:ENTITY, xs:float, xs:gDay, xs:gMonth, xs:gMonthDay, xs:gYear, xs:gYearMonth, xs:hexBinary, xs:ID, xs:IDREF, xs:int, xs:integer, xs:language, xs:long, xs:Name, xs:NCName, xs:negativeInteger, xs:NMTOKEN, xs:nonNegativeInteger, xs:nonPositiveInteger, xs:normalizedString, xs:NOTATION, xs:positiveInteger, xs:QName, xs:short, xs:string, xs:time, xs:token, xs:unsignedByte, xs:unsignedInt, xs:unsignedLong, xs:unsignedShort

Description

xs:pattern defines regular-expression patterns over the lexical space. Their notation is borrowed from the regular expressions of Perl and extended to support Unicode character blocks.

If several xs:pattern facets are defined in one derivation step, a value is valid if at least one pattern matches it. In other words, a logical OR applies to all patterns in the same step.

Patterns apply to the base data type’s lexical space. A logical AND therefore applies to patterns defined in different derivation steps.

Pattern notation is explained in detail in Regular expressions for specifying simple data types.

Restrictions

xs:pattern is a common workaround for defining data types that appear to be missing from the predefined set. For example, patterns can simulate decimal numbers with a separator other than a period. Such types must be based on xs:token and have neither the semantics of xs:decimal nor its set of facets.

xs:pattern cannot be fixed.

Example

<xs:simpleType name="nonScientific">
    <xs:restriction base="xs:float">
        <xs:pattern value="[^eE]*"/>
    </xs:restriction>
</xs:simpleType>
<xs:simpleType name="noLeading0">
    <xs:restriction base="xs:float">
        <xs:pattern value="[^0].*"/>
    </xs:restriction>
</xs:simpleType>

Attributes

id
Element ID according to W3C XML Schema.

value
Facet value.

   

 

 

 

back to top