Chapter 14. Regular Expressions

IN THIS CHAPTER

14.1 Concepts and Observations

14.2 Regular Expression Syntax

14.3 Constraining Simple Content

A regular expression is a pattern for identifying a range of string values. This pattern conforms to a specific grammar. The Schema Recommendation suggests that an XML validator should implement “Level 1” regular expressions as defined in the Unicode Regular Expression Guidelines. These guidelines reside at http://unicode.org/unicode/reports/tr18/.

An expression (without “regular”) is a regular expression snippet, or a part of a regular expression. An expression may match one or many characters. An expression may comprise an entire regular expression.

Notation Note

In this chapter, all strings that might appear in an XML instance appear in double quotes (for example, “a sample value”). This is different from most of the rest of book. There are so many quoted regular expressions (for example, ‘reg.*exp?’) and corresponding instance values, that the visual distinction between schema values and instance values is valuable. Occasionally, the instance value contains line delimiters, such as:

"this string contains 
a line break" 

Additionally, some instance values contain meaningful spaces (unlike elements in an XML schema document), that would be difficult to see if no quotes were presented.


A simple type in an XML schema (or a complex type constrained to simple content) specifies a regular expression with a restriction element that contains a pattern element. Section 14.4 demonstrates generally how to specify simple types that incorporate regular expressions to constrain element instance values. Chapter 10 provides detail on the pattern element.

An XML validator can validate appropriate values in an XML instance against a regular expression specified by a simple type. The validation assures that each string value in the XML instance conforms to the appropriate set of regular expressions.

This chapter assumes an understanding of XML schemas in general (specifically any chapter before this one). Furthermore, for simplicity, most of this chapter discusses only the regular expressions, not the simple or complex types that incorporate the regular expression. All of the XML schema examples in this chapter describe a regular expression and a set of strings that validate against that regular expression. This chapter skips discussion of element types, element instances, attribute types, and attribute instances, although an XML validator requires these to create and validate an XML instance.

All the regular expressions described in this chapter come from regexpDemo.xsd. Similarly, regexpDemo.xml contains the strings that purport to be valid in a corresponding XML instance. Both of these files are online at http://www.XMLSchemaReference.com/examples/Ch14.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.216.74