XML_Schemas_Tổng hợp
<XML_Schemas>Bài 6: Bài tập tổng hợp trên lớp.
1. File contacts.xml.
<?xml version="1.0" encoding="UTF-8"?>
<contacts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://exam.com/contact contact.xsd"
xmlns:n = "http://exam.com/name"
xmlns = "http://exam.com/contact"
>
<contact contact_ID = "M581626" know="M581626" gender="Male" blog="http:\\www.nguyenphutuvnua.blogspot.com\2016\05\xmlschemasattribute.html">
<name>
<n:firstname>Nguyen</n:firstname>
<n:midname></n:midname>
<n:lastname>Tu</n:lastname>
</name>
<location>
<address></address>
</location>
<phone type="Home" >7666</phone>
<decription>
<br></br>
</decription>
</contact>
<contact contact_ID = "M583626" know="M581626 M583626" gender="Female" blog="http:\\www.nguyenphutuvnua.blogspot.com\2016\05\xmlschemasattribute.html" emails="nguyentudb1995@gmail.com">
<name>
<n:firstname>Nguyen</n:firstname>
<n:lastname>Tu</n:lastname>
</name>
<location>
<address></address>
</location>
<phone type="Cell">78887</phone>
<decription>
<br/>
</decription>
</contact>
</contacts>
2. File contact.xsd
2.1 Phần tử "contacts"
<xsd:element name="contacts"><xsd:complexType>
<xsd:sequence>
<xsd:element name="contact" type="complexType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
2.2 Phần tử "contact"
<xsd:element name="contact" type="complexType" minOccurs="0" maxOccurs="unbounded"/>
<xsd:complexType name="complexType">
<xsd:sequence>
<xsd:element name="name" type="name"/>
<xsd:element name="location" type="location"/>
<xsd:element name="phone">
<xsd:complexType mixed="true">
<xsd:attribute name="type" type="phoneType" use="required"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="decription" type="discription"/>
</xsd:sequence>
<xsd:attribute name="contact_ID" type="xsd:ID" use="required"/>
<xsd:attribute name="know" type="xsd:IDREFS" use="optional"/>
<xsd:attribute name="gender" type="gender" use="required"/>
<xsd:attribute name="blog" type="blog" use="optional"/>
<xsd:attribute name="emails" type="email" use="optional"/>
</xsd:complexType>
2.3 Phần tử "name"
<xsd:element name="name" type="name"/>
<xsd:complexType name="name">
<xsd:sequence>
<xsd:element name="firstname" type="flName"/>
<xsd:element name="midname" type="midName" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="lastname" type="flName"/>
</xsd:sequence>
</xsd:complexType>
<xsd:simpleType name="midName">
<xsd:restriction base="xsd:string">
<xsd:minLength value="0"/>
<xsd:maxLength value="50"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="flName">
<xsd:restriction base="xsd:string">
<xsd:minLength value="1"/>
<xsd:maxLength value="50"/>
<xsd:pattern value="[a-zA-Z]{1,20}"/>
</xsd:restriction>
</xsd:simpleType>
2.4 Phần tử "location"
<xsd:element name="location" type="location"/>
<xsd:complexType name="location">
<xsd:choice>
<xsd:element name="address" type="xsd:string"/>
<xsd:sequence>
<xsd:element name="latitude" type="xsd:string"/>
<xsd:element name="longitude" type="xsd:string"/>
</xsd:sequence>
</xsd:choice>
</xsd:complexType>
2.5 Phần tử "phone"
<xsd:element name="phone">
<xsd:complexType mixed="true">
<xsd:attribute name="type" type="phoneType" use="required"/>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="phoneType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Home"/>
<xsd:enumeration value="Fax"/>
<xsd:enumeration value="Work"/>
<xsd:enumeration value="Cell"/>
</xsd:restriction>
</xsd:simpleType>
2.6 Phần tử "decription"
<xsd:element name="decription" type="discription"/>
<xsd:complexType name="discription" mixed="true">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="b" type="xsd:string"/>
<xsd:element name="u" type="xsd:string"/>
<xsd:element name="i" type="xsd:string"/>
<xsd:element name="em" type="xsd:string"/>
<xsd:sequence>
<xsd:element name="br">
<xsd:complexType>
<xsd:attribute name="br" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:element name="strong" type="xsd:string"/>
</xsd:choice>
</xsd:complexType>
2.7 Các thuộc tính
2.7.1 contact_ID
Dữ kiệu kiểu ID và bắt buộc 1 contact phải có 1 "contact_ID".
<xsd:attribute name="contact_ID" type="xsd:ID" use="required"/>
2.7.2 know(ID list)
Dữ kiệu kiểu IDREFS và 1 contact phải có thể có hoặc không 1 "know".
<xsd:attribute name="know" type="xsd:IDREFS" use="optional"/>
2.7.3 gender
Dữ kiệu chỉ có thể chọn male|female và 1 contact phải có "gender".
<xsd:attribute name="gender" type="gender" use="required"/>
<xsd:simpleType name="gender">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Male"/>
<xsd:enumeration value="Female"/>
</xsd:restriction>
</xsd:simpleType>
2.7.4 blog
Thuộc tính blog phải có định dạng chuẩn http:\\www."abcd...".blogspot.com\"..."\"...".html.
<xsd:attribute name="blog" type="blog" use="optional"/>
<xsd:simpleType name="blog">
<xsd:restriction base="xsd:string">
<xsd:pattern value="((http|ftp|smtp):\\\\www\.\w{6,30}\.blogspot\.(com|edu|gov) (\\\w{2,10}){0,5}\\\w{0,50}\.html)"/>
</xsd:restriction>
</xsd:simpleType>
2.7.5 email
Thuộc tính email phải có định dạng chuẩn "...."@"...".com.
<xsd:attribute name="emails" type="email" use="optional"/>
<xsd:simpleType name="email">
<xsd:restriction base="xsd:string">
<xsd:pattern value="([a-z]([a-z0-9]){4,50}@[a-z]{3,10}\.(com|edu|qov))"/>
</xsd:restriction>
</xsd:simpleType>
Chúc các bạn thành công.
No Comment to " XML_Schemas_Tổng hợp "