องค์ประกอบ extension ของ XML Schema
การประกาศและการใช้งาน
องค์ประกอบ extension มีความหมายที่จะขยายองค์ประกอบ simpleType หรือ complexType。
ข้อมูลองค์ประกอบ
ความเกี่ยวข้อง | หนึ่งครั้ง |
องค์ประกอบพ่อ | complexContent |
เนื้อหา | annotation、attribute、attributeGroup、anyAttribute、choice、all、sequence、group |
รูปแบบ
<extension id=ID base=QName attributes ทั้งหมด > (annotation?,((group|all|choice|sequence)?, ((attribute|attributeGroup)*,anyAttribute?))) </extension>
ตัวแปร | รายละเอียด |
---|---|
id | ตัวเลือก |
base | จำเป็น |
xml:lang | ตัวเลือก |
(? สัญญาณการประกาศในองค์ประกอบ extension ซึ่งสามารถปรากฏขึ้นได้ฉบับเดียวหรือไม่มีฉบับเดียว สัญญาณ * ประกาศว่าองค์ประกอบนี้สามารถปรากฏขึ้นได้ฉบับเดียวหรือหลายฉบับ)。
ตัวอย่าง
ตัวอย่าง 1
ตัวอย่างดังนี้ ผ่านการเพิ่ม attribute มีการขยาย 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
ตัวอย่างดังนี้ ผ่านการเพิ่มประกายสามองค์ มีการขยาย element ของ 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>