XML Schema group 元素
定義和用法
group 元素用於定義在複雜類型定義中使用的元素組。
元素信息
出現次數 | 無限制 |
父元素 | schema、choice、sequence、complexType、restriction (complexContent)、extension (complexContent) |
內容 | annotation、all、choice、sequence |
กฎศัพท์
<group id=ID name=NCName ref=QName maxOccurs=nonNegativeInteger|unbounded minOccurs=nonNegativeInteger attributes > annotation?,(all|choice|sequence)?) </group>
(? สัญญาณอ้างอิงปรากฏใน element ของ group ซึ่งสามารถปรากฏขึ้นหรือไม่ปรากฏขึ้นได้。)
attribute
id
เลือกตั้งได้。กำหนด ID ที่เป็นเดียวกันของ element
name
เลือกตั้งได้。กำหนดชื่อของกลุ่ม ชื่อนี้ต้องเป็น NCName ที่ถูกกำหนดใน XML Namespace Specification
ใช้คุณสมบัตินี้เฉพาะในกรณีที่ element ของ schema เป็น parent element ของ group ในกรณีนี้ group จะถูกใช้โดย model group ของ element complexType หรือ choice หรือ sequence
attribute ของ name และ ref ไม่สามารถปรากฏพร้อมกัน
ref
เลือกตั้งได้。อ้างอิงชื่อของ group อื่นๆ ค่า ref ต้องเป็น QName ค่า ref สามารถมีชื่อหน้ากากของชื่อพื้นฐาน
attribute ของ name และ ref ไม่สามารถปรากฏพร้อมกัน
maxOccurs
เลือกตั้งได้。กำหนดจำนวนครั้งของการปรากฏของ element ที่อาจมี group ในฐานะ parent element คือตัวเลขเฉพาะที่มากกว่าหรือเท่ากับ 0 หรือใช้คำว่า "unbounded" ถ้าไม่ต้องการกำหนดจำนวนครั้งของการปรากฏของการปรากฏของการปรากฏของ element คือ 1
minOccurs
เลือกตั้งได้。กำหนดจำนวนครั้งของการปรากฏของ element ที่อาจมี group ในฐานะ parent element คือตัวเลขเฉพาะที่มากกว่าหรือเท่ากับ 0 ด้วยค่าเริ่มต้นคือ 1
attributes
เลือกตั้งได้。กำหนดคุณสมบัติอื่นที่มีชื่อนอกโครงสร้าง Schema
ตัวอย่าง
ตัวอย่าง 1
ตัวอย่างดังนี้กำหนดกลุ่มเซอรีส์ที่มีสมาชิกสี่อันดับและใช้ประกาศ group ในการกำหนดชนิดของปริมาณแบบฝึกหัด
<?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:group name="custGroup"> <xs:sequence> <xs:element name="customer" type="xs:string"/> <xs:element name="orderdetails" type="xs:string"/> <xs:element name="billto" type="xs:string"/> <xs:element name="shipto" type="xs:string"/> </xs:sequence> </xs:group> <xs:element name="order" type="ordertype"/> <xs:complexType name="ordertype"> <xs:group ref="custGroup"/> <xs:attribute name="status" type="xs:string"/> </xs:complexType> </xs:schema>