The best XML Schema defines / Facets Tutorial In 2024, In this tutorial you can learn Limiting values,Defining a set of values,A series of limited value,A series of values defined for other,Blank character defined,Of defined length,Defined data types,
Limited (restriction) is used to define acceptable XML element or attribute values. To define XML elements are called facet.
The following example defines an element with a defined and named "age" of. The value of age can not be lower than 0 or greater than 120:
For the contents of the XML element is limited to a set of acceptable values, we would use the enumeration constraint (enumeration constraint).
The following example defines an element with a qualified name "car" is. Only acceptable values are: Audi, Golf, BMW:
The above example can also be written as:
Note: In this case, type "carType" can be used by other elements because it is not part of the "car" element.
To limit the content of an XML element is defined as a series of numbers or letters that can be used, we want to use the mode confinement (pattern constraint).
The following example defines an element with a defined called "letter" of. The only acceptable values lowercase letters a - z one:
The next example defines an element with a defined called "initials" of. Acceptable values are uppercase letters A - Z in which three of them:
The next example also defines an element with a defined called "initials" of. Acceptable values are uppercase or lowercase letters a - z three of them:
The next example defines an element with a limited choice called "acceptable value is the letters x, y or z in a:
The next example defines an element with a qualified name "prodid" of. Acceptable values are a sequence of five digits, and each number in the range of 0-9:
The following example defines an element with a defined called "letter" of. Acceptable values are a - z zero or more letters:
The following example defines an element with a defined called "letter" of. Acceptable values are one or more pairs of letters, each pair consists of a lowercase letter followed by an uppercase letter. For example, "sToP" will validate this model, but the "Stop", "STOP" or "stop" can not be verified:
The following example defines an element with a defined called "gender" is. Acceptable values are male or female:
The following example defines an element with a qualified name "password" of. Acceptable values are a row of characters consists of eight characters, these characters must be uppercase or lowercase letters a - z or will digital 0--9:
To specify white space characters (whitespace characters) approach, we need to use whiteSpace limited.
The following example defines a named "address" element with a defined. This whiteSpace Limited is set to "preserve", which means that the XML processor will not remove any white space characters:
This example also defines a named "address" element with a defined. This whiteSpace Limited is set to "replace", which means that the XML processor will remove all white space characters (line breaks, carriage returns, spaces, and tabs):
This example also defines a named "address" element with a defined. This whiteSpace Limited is set to "collapse", which means that the XML processor will remove all white space characters (line breaks, carriage returns, spaces, and tabs are replaced with spaces, leading and trailing spaces will be removed, and multiple consecutive spaces are reduced to a single space):
To limit the length of the element values, we need to use the length, maxLength and minLength limited.
Elements with a defined and named "password" in this case is defined. Its value must be exactly eight characters:
This example also defines an element with a qualified name "password" of. Its value is a minimum of 5 characters and a maximum of eight characters:
limited | description |
---|---|
enumeration | Define a list of acceptable values |
fractionDigits | It defines the maximum allowed number of decimal places. It must be greater than 0. |
length | Define the exact number of allowed characters or list items. It must be greater than or equal to 0. |
maxExclusive | Define the upper limit value. Permitted value must be less than this value. |
maxInclusive | Define the upper limit value. Allowed value must be less than or equal to this value. |
maxLength | Defines the maximum number of allowed characters or list items. It must be greater than or equal to 0. |
minExclusive | The lower limit value is defined. The value must be allowed greater than this value. |
minInclusive | The lower limit value is defined. Allowed value must greater than or equal to this value. |
minLength | Defines the allowed minimum number of characters or list items. It must be greater than or equal to 0. |
pattern | Define the exact sequence of acceptable characters. |
totalDigits | It defines the allowed precision-digit Arabic numerals. It must be greater than 0. |
whiteSpace | The definition of white space characters (line breaks, carriage returns, tabs and spaces) are handled. |