Latest web development tutorials

XML Schema องค์ประกอบข้อ จำกัด

XML Schema อ้างอิง XML Schema สมบูรณ์อ้างอิง

ความหมายและการใช้งาน

นิยามองค์ประกอบข้อ จำกัด 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>

(เข้าสู่ระบบประกาศว่าองค์ประกอบที่ข้อ จำกัด ขององค์ประกอบสามารถเกิดขึ้นได้เป็นศูนย์หรือเพียงครั้งเดียว.)

属性 描述
id 可选。规定该元素的唯一的 ID。
base 必需。规定在该 schema(或由指定的命名空间指示的其他 schema)中定义的内建数据类型、simpleType 或 complexType 元素的名称。
any attributes 可选。规定带有 non-schema 命名空间的任何其他属性。

ตัวอย่างที่ 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

ตัวอย่างนี้กำหนด "ชื่อย่อ" องค์ประกอบชื่อ "ชื่อย่อ" องค์ประกอบเป็นชนิดที่เรียบง่ายด้วยข้อ จำกัด ค่าที่ยอมรับจาก 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

ตัวอย่างนี้แสดงประเภทที่ซับซ้อนกำหนดโดยใช้ข้อ จำกัด ประเภทที่ซับซ้อน "Chinese_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 Schema อ้างอิง XML Schema สมบูรณ์อ้างอิง