A simple element can not contain attributes, if an element
contains attributes item it is considered as complex type.
Syntax:
<xs: attribute name=”xxx” type=”yyy” />
Declaring an attribute with a fixed value
Syntax: <xs: attribute
name=”xxx” type=”yyy” fixed=”value”/>
Declaring an
attribute that is: either optional (or)
mandatory:
Syntax:
<xs: attribute name=”xxx” type=”yyy”
use=”optional/required”/>
Restrictions:
To allow the user to type acceptable value for the XML elements.
The restrictions on XML elements are called as facets.
What is a facet?
It allows the users to type acceptable value for the XML
elements. These restrictions on XML elements are called facets.
Restrictions on range
of values:
Syntax:
<xs: element name=”xxx”>
<xs:
simpleType>
<xs: restriction base=”yyy”>
<xs:
mininclusive value=”minvalue”/>
<xs:
maxinclusive value=”maxvalue”/>
</xs:
restriction>
</xs:simpleType>
</xs: element>
·
Instead of mininclusive and maxinclusive we can
write minExclusive and MaxExclusive.
·
We can combine also
·
In minInclusive and MaxInclusive we can include
the extreme values where as in MinExclusive and MaxExclusive, we can not
include extreme values.
Restrictions on List
of values:
<xs: element name=”xxx”>
<xs: simpleType>
<xs:restriction
base=”yyy”>
<xs:enumeration
value=”value1”/>
<xs:
enumeration value=”value2”/>
<xs:
enumeration value=”value3”/>
</xs: restriction>
</xs: simpleType>
</xs: element>
Patterns:
Syntax:
<xs: element name=”xxx”>
<xs:
simpleType>
<xs:restriction base=”yyy”>
<xs: pattern value=”[a..z],[a-z]”/>
</xs: restriction>
</xs:simpleType>
</xs:element>
·
The above pattern indicating the length of the data
to be three characters and the characters must be only lower case alphabets.
Patterns2:
<xs: pattern value=”[a-zA-Z][a-Za-z]”/>
·
The above pattern indicates that the data must
contain two characters and the characters can be either lower case alphabets or
uppercase alphabets.
Patterns3:
<xs: pattern value=”[aeiou]”/>
·
The above pattern indicates the data can contain
only one character among a,e,I,o,u
Pattern4:
<xs: pattern value=”[0-9][0-9]”/>
·
The above pattern indicates that data should
contain exactly two digits.
Pattern5:
<xs:pattern value=”([a-z])*”/>
·
The above pattern indicates that data can
contain 0 or more characters and the characters should be only lower case
alphabets.
Pattern6:
<xs: pattern value=”([a-z][A-Z])+”/>
·
The above pattern indicates that data can contain
even number of characters and it should contain min/max two characters out of
which the first one is lower case alphabet the second one is upper case
alphabet
Pattern7:
<xs: pattern
value=”[0-9]{10}”/>
·
The above pattern indicates that the data must
contain exactly ten(10) digits.
No comments:
Post a Comment