XML SCHEMA
An XML document with correct syntax is called
"Well Formed".
An XML document validated against an XML Schema
is both "Well Formed" and "Valid".
XML Schema language is also referred to as
XML Schema Definition (XSD).
---------------------------------------------------------------------------------
"note.xsd"
- <?xml version="1.0"?>
- <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
- targetNamespace="https://www.w3schools.com"
- xmlns="https://www.w3schools.com"
- elementFormDefault="qualified">
- <xs:element name="note">
- <xs:complexType>
- <xs:sequence>
- <xs:element name="to" type="xs:string"/>
- <xs:element name="from" type="xs:string"/>
- <xs:element name="heading" type="xs:string"/>
- <xs:element name="body" type="xs:string"/>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
- </xs:schema>
- element note ประกอบด้วย element จึงใช้ complexType
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
<note>
<date>2015-09-01</date>
<hour>08:30</hour>
<to>Tove</to>
<from>Jani</from>
<body>Don't forget me this
weekend!</body>
</note>
---------------------------------------------------------------------------------
"note.xml"
<?xml version="1.0"?>
<note
xmlns="https://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.w3schools.com/xml/note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Type , default , fixed , required
xs:string
xs:decimal
xs:integer
xs:boolean
xs:date
xs:time
<xs:element name="color" type="xs:string" default="red"/>
<xs:element name="color" type="xs:string" fixed="red"/>
<xs:attribute name="lang" type="xs:string" use="required"/>
Restrictions ตัวอย่าง
ค่าสูงสุดต่ำสุด .
- <xs:restriction base="xs:integer">
- <xs:minInclusive value="0"/>
- <xs:maxInclusive value="120"/> </xs:restriction>
รับเฉพาะ string ที่กำหนด
- <xs:restriction base="xs:string">
- <xs:enumeration value="Audi"/>
- <xs:enumeration value="Golf"/>
- <xs:enumeration value="BMW"/>
- </xs:restriction>
- <xs:restriction base="xs:string">
- <xs:pattern value="[a-zA-Z][a-zA-Z][a-zA-Z]"/>
</xs:restriction>
และยังมีข้อจำกัดอื่นๆ
ที่สามารถกำหนดได้
---------------------------------------
< อ้างอิงรูปและ โค้ดจาก W3SCHOOL >
ไม่มีความคิดเห็น:
แสดงความคิดเห็น