May 28, 2021 XML Schema
2. The qualification of the value
3. The qualification of a set of values
4. The qualification of a series of values
5. Additional qualifications for a series of values
Qualifiers are used to define acceptable values for XML elements or properties. The qualification of an XML element is called facet.
The following example defines an element with a qualification and the name "age". The value of age cannot be less than 0 or higher than 120:
To limit the contents of an XML element to an acceptable set of values, we use enumeration constraints.
The following example defines an element with a qualified name called "car". Acceptable values are: Audi, Golf, BMW:
The above example can also be written as:
Note: In this case, the type "carType" can be used by other elements because it is not part of the "car" element.
To define the content limits of XML elements as a series of available numbers or letters, we use pattern constraints.
The following example defines an element with a qualified name called "letter". The acceptable value is only the lowercase letter a - z one of them:
The next example defines an element with a qualification called "initials". The acceptable value is three of the capital letters A - Z:
The next example also defines an element with a qualification called "initials". The acceptable values are three of the capital or lowercase letters a - z:
The next example defines an element with a qualification called "choice." The acceptable value is one of the letters x, y, or z:
The next example defines an element with a qualification called "prodid". The acceptable value is a sequence of five Arabic numerals, and the range of each number is 0-9:
The following example defines an element with a qualified name called "letter". The acceptable value is zero or more letters in a - z:
The following example defines an element with a qualified name called "letter". A n acceptable value is a pair or more of letters, each consisting of a lowercase letter followed by a capital letter. For example, "sToP" will pass this pattern, but "Stop," "STOP," or "stop" will not:
The following example defines an element with a qualified name called "gender". The acceptable value is male or female:
The following example defines an element with a qualified name called "password". The acceptable value is a line of 8 characters that must be capital or lowercase a -z or the number 0 - 9:
To specify how whitespace characters are handled, we need to use whiteSpace qualification.
The following example defines an element with a qualified name called "address". This whiteSpace qualification is set to "preserve," which means that the XML processor does not remove any blank characters:
This example also defines an element with a qualified name called "address". This whiteSpace qualification is set to "replace," which means that the XML processor removes all blank characters (line breaks, carriage returns, spaces, and tabs):
This example also defines an element with a qualified name called "address". This whiteSpace qualification is set to "collapse," which means that the XML processor will remove all blank characters (line breaks, carriage returns, spaces, and tabs will be replaced with spaces, spaces at the beginning and end will be removed, and multiple consecutive spaces will be reduced to a single space):
To limit the length of the element's middle value, we need to use length, maxLength, and minLength qualification.
This example defines an element with a qualified name called "password". Its value must be accurate to 8 characters:
This example also defines an element with a qualified name called "password". It has a minimum value of 5 characters and a maximum of 8 characters:
Qualified | Describe |
---|---|
enumeration | Define a list of acceptable values |
fractionDigits | Defines the maximum number of scales allowed. Must be greater than or equal to 0. |
length | Defines the exact number of characters or list items that are allowed. Must be greater than or equal to 0. |
maxExclusive | Defines the upper limit of the value. The allowed value must be less than this value. |
maxInclusive | Defines the upper limit of the value. The allowed value must be less than or equal to this value. |
maxLength | Defines the maximum number of characters or list items allowed. Must be greater than or equal to 0. |
minExclusive | Defines the lower limit of the value. The allowed value must be greater than this value. |
minInclusive | Defines the lower limit of the value. The allowed value must be greater than or equal to this value. |
minLength | Defines the minimum number of characters or list items allowed. Must be greater than or equal to 0. |
pattern | Defines an exact sequence of acceptable characters. |
totalDigits | Defines the exact number of arabic numerals allowed. Must be greater than 0. |
whiteSpace | Defines how blank characters (line breaks, carriage returns, spaces, and tabs) are handled. |