องค์ประกอบข้อจำกัดสคีมา XML
❮ การอ้างอิงสคีมา XML ที่สมบูรณ์
ความหมายและการใช้งาน
อิลิเมนต์การจำกัดกำหนดข้อจำกัดในนิยาม simpleType, simpleContent หรือ complexContent
ข้อมูลองค์ประกอบ
- องค์ประกอบหลัก: simpleType, simpleContent, complexContent
ไวยากรณ์
<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>
(เครื่องหมาย ? ประกาศว่าองค์ประกอบสามารถเกิดขึ้นได้เป็นศูนย์หรือครั้งเดียวภายในองค์ประกอบข้อจำกัด)
Attribute | Description |
---|---|
id | Optional. Specifies a unique ID for the element |
base |
Required. Specifies the name of a built-in data type, simpleType element, or complexType element defined in this schema or another schema |
any attributes | Optional. Specifies any other attributes with non-schema namespace |
ตัวอย่าง 1
ตัวอย่างนี้กำหนดองค์ประกอบที่เรียกว่า "อายุ" โดยมีข้อจำกัด ค่าของอายุต้องไม่ต่ำกว่า 0 หรือมากกว่า 100:
<xs:element name="age">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
ตัวอย่าง 2
ตัวอย่างนี้ยังกำหนดองค์ประกอบที่เรียกว่า "ชื่อย่อ" องค์ประกอบ "ชื่อย่อ" เป็นประเภทธรรมดาที่มีข้อจำกัด ค่าเดียวที่ยอมรับได้คือตัวอักษร LOWERCASE OR UPPERCASE สามตัวจาก a ถึง z:
<xs:element name="initials">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z][a-zA-Z][a-zA-Z]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
ตัวอย่างที่ 3
ตัวอย่างนี้กำหนดองค์ประกอบที่เรียกว่า "รหัสผ่าน" องค์ประกอบ "รหัสผ่าน" เป็นประเภทธรรมดาที่มีข้อจำกัด ค่าต้องมีอักขระอย่างน้อยห้าตัวและสูงสุดแปดอักขระ:
<xs:element name="password">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="5"/>
<xs:maxLength value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
ตัวอย่างที่ 4
ตัวอย่างนี้แสดงคำจำกัดความประเภทที่ซับซ้อนโดยใช้ข้อจำกัด ประเภทที่ซับซ้อน "Norwegian_customer" ได้มาจากประเภทที่ซับซ้อนของลูกค้าทั่วไป และองค์ประกอบประเทศถูกกำหนดเป็น "นอร์เวย์":
<xs:complexType name="customer">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Norwegian_customer">
<xs:complexContent>
<xs:restriction base="customer">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="country" type="xs:string" fixed="Norway"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
❮ การอ้างอิงสคีมา XML ที่สมบูรณ์