Latest web development tutorials

XML Schema องค์ประกอบส่วนขยาย

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

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

องค์ประกอบการขยายตัวของ simpleType หรือองค์ประกอบ complexType สำหรับการขยายตัว

องค์ประกอบข้อมูล

  • องค์ประกอบหลัก: simpleContent, complexContent

ไวยากรณ์

<extension
id=ID
base=QName
any attributes
>

(annotation?,((group|all|choice|sequence)?,
((attribute|attributeGroup)*,anyAttribute?)))

</extension>

(ใช่หรือไม่ลงประกาศในองค์ประกอบของการขยายซึ่งสามารถปรากฏเป็นศูนย์หรือครั้งเดียวเครื่องหมาย * ประกาศว่าองค์ประกอบสามารถเกิดขึ้นได้เป็นศูนย์หรือมากกว่าครั้ง.)

คุณสมบัติ ลักษณะ
ID ไม่จำเป็น มันระบุรหัสเฉพาะสำหรับองค์ประกอบ
ฐาน จำเป็นต้องใช้ Built-ชื่อชนิดข้อมูลระบุ simpleType หรือ complexType องค์ประกอบ
XML: Lang ไม่จำเป็น มันกำหนดภาษาที่ใช้ในเนื้อหา

ตัวอย่างที่ 1

ตัวอย่างต่อไปนี้โดยการเพิ่มคุณสมบัติที่จะขยาย simpleType ที่มีอยู่:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:simpleType name="size">
<xs:restriction base="xs:string">
<xs:enumeration value="small" />
<xs:enumeration value="medium" />
<xs:enumeration value="large" />
</xs:restriction>
</xs:simpleType>

<xs:complexType name="jeans">
<xs:simpleContent>
<xs:extension base="size">
<xs:attribute name="sex">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="male" />
<xs:enumeration value="female" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

</xs:schema>

ตัวอย่างที่ 2

ตัวอย่างต่อไปนี้โดยการเพิ่มองค์ประกอบสามไปยังส่วนขยายองค์ประกอบ complexType ที่มีอยู่:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="employee" type="fullpersoninfo"/>

<xs:complexType name="personinfo">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="fullpersoninfo">
<xs:complexContent>
<xs:extension base="personinfo">
<xs:sequence>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

</xs:schema>


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