XML_Schemas_simpleType
<XML_Schemas>Bài 5: simpleType
1. Cú pháp
<simpleType
id=ID
name=NCName
any attributes
>
(annotation?,(restriction|list|union))
</simpleType>
id=ID
name=NCName
any attributes
>
(annotation?,(restriction|list|union))
</simpleType>
Trên lớp ta thường quan tâm đến phần trong nó là " restriction|list|union ".
id : ID của Type
name : Tên của Type.
2.Restriction
<restriction
id=ID
base=QName
any attributes
>
Content for simpleType:
(annotation?,(simpleType?,(minExclusive|minInclusive|
maxExclusive|maxInclusive|totalDigits|fractionDigits|
length|minLength|maxLength|enumeration|whiteSpace|pattern)*))
Content for simpleContent:
(annotation?,(simpleType?,(minExclusive |minInclusive|
maxExclusive|maxInclusive|totalDigits|fractionDigits|
length|minLength|maxLength|enumeration|whiteSpace|pattern)*)?,
((attribute|attributeGroup)*,anyAttribute?))
Content for complexContent:
(annotation?,(group|all|choice|sequence)?,
((attribute|attributeGroup)*,anyAttribute?))
</restriction>
id=ID
base=QName
any attributes
>
Content for simpleType:
(annotation?,(simpleType?,(minExclusive|minInclusive|
maxExclusive|maxInclusive|totalDigits|fractionDigits|
length|minLength|maxLength|enumeration|whiteSpace|pattern)*))
Content for simpleContent:
(annotation?,(simpleType?,(minExclusive |minInclusive|
maxExclusive|maxInclusive|totalDigits|fractionDigits|
length|minLength|maxLength|enumeration|whiteSpace|pattern)*)?,
((attribute|attributeGroup)*,anyAttribute?))
Content for complexContent:
(annotation?,(group|all|choice|sequence)?,
((attribute|attributeGroup)*,anyAttribute?))
</restriction>
Ví dụ 1 :
<xsd:element name="age">
<xsd:simpleType>
<xsd:restriction base="xsd:integer">
<xsd:minInclusive value="0"/>
<xsd:maxInclusive value="100"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:simpleType>
<xsd:restriction base="xsd:integer">
<xsd:minInclusive value="0"/>
<xsd:maxInclusive value="100"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
Thuộc tính tuổi<age> có kiểu dữ liệu là integer và lằm trong khoảng từ [0 - 100].
Ví dụ 2 :
<xsd:simpleType name = "fname">
<xsd:restriction base="xsd:string">
<xsd:pattern value="[a-zA-Z]{1,20}"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="[a-zA-Z]{1,20}"/>
</xsd:restriction>
</xsd:simpleType>
Tạo 1 kiểu có tên là "fname" base trên kiểu string dữ liệu của kiểu chỉ nhận các kí tự chữ in thường và in hoa.Tối thiểu 1 kí tự tối đa 20 kí tự.
Ví dụ 3 :
<xsd:simpleType name = "lname">
<xsd:restriction base="xsd:string">
<xsd:minLength value="3"/>
<xsd:maxLength value="20"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:minLength value="3"/>
<xsd:maxLength value="20"/>
</xsd:restriction>
</xsd:simpleType>
Tạo 1 kiểu có tên là "lname" base trên kiểu string.Tối thiểu 5 kí tự tối đa 20 kí tự.
Ví dụ 4 :
<simpleType name="phoneType">
<restriction base="string">
<enumeration value="Home"/>
<enumeration value="Work"/>
<enumeration value="Cell"/>
<enumeration value="Fax"/>
</restriction>
</simpleType>
Tạo 1 kiểu có tên là "phonType" base trên kiểu string.Chỉ nhận các giá trị là : Home | Work | Cell | Fax.
3. Pattern
- "." 1 kí tự bất kì.
- "\d" 1 kí tự số (0 - 9).
- "\w" 1 kí tự văn bản (a - z A - Z).
- "\D" kí tự không phải là số.
- "\W" kí tự không phải là kí tự chữ.
- "\t" kí tự Tab.
- "\n" kí tự xuống dòng .
- "\." kí tự ".".
- "[]" đoạn. VD: [0 9], [a z].
- "()" nhóm.
- "{m,n}" lặp min = m , max = n lần.
- "{m}" lặp đúng m lần.
- "+" một hoặc nhiều.
- "*" không hoặc nhiều.
- "?" 1 hoặc 0.
- "|" hoặc.
Ví dụ:
<xsd:pattern value="[a-zA-Z]{1,20}"/>
Từ 1 - 20 kí tự có giá trị trong khoảng [a - z] [A - Z].
<xsd:pattern value="male|female"/>
Chỉ nhận 1 trong 2 giá trị "male" hoặc "female".
<xsd:pattern value="\w{10}"/>
Đúng 10 kí tự văn bản.
Ví dụ 2:
Thuộc tính blog có dạng : http:\\www.nguyenphutuvnua.blogspot.com\2016\05\xmlschemasattribute.html
<xsd:pattern
value="((http|ftp|smtp):\\\\www\.\w{6,30}\.blogspot\.(com|edu|gov)(\\\w{2,10}){0,5}\\\w{0,50}\.html)"
/>
Chúc các bạn thành công.
No Comment to " XML_Schemas_simpleType "