XML technologies / XML Schema / Regular expressions for specifying simple datatypes / The Swiss Army knife
(Excerpt from "XML Schema" by Eric van der Vlist)
Patterns, and regular expressions generally, are like a Swiss Army knife for restricting simple datatypes. They are highly flexible, compensate for many limitations of other facets, and often define custom datatypes for formats such as ISBNs, phone numbers or particular date formats. Like Swiss Army knives, however, patterns have limits.
Datatypes with multiple ranges, such as integers from –1 to 5 or 10 to 15, can be defined as a union of types covering each range. We could unite a type accepting integers from –1 to 5 with one accepting 10 to 15. However, the resulting union loses its integer semantics and cannot be further restricted by integer facets. Patterns provide another solution: although less readable than unions, they preserve the base type’s semantics.
Sawing down a tree with a Swiss Army knife is slow, tiring and dangerous. Regular expressions can also be slow, tiring and dangerous to write as combinations multiply. Keep them as simple as possible.
A Swiss Army knife cannot turn lead into gold, and no facet can change a datatype’s primary type. A string restricted to a particular date format remains a string and never acquires date-time facets. Thus there is no practical way to express localized date formats.
Copyright © 2003 O'Reilly Verlag GmbH & Co. KG
You may print the online version for private use.
Otherwise, this chapter from "XML Schema" is subject to the same terms as the bound edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de
back to top