องค์ประกอบ complexType ของ XML Schema

คำนิยามและวิธีใช้

complexType องค์ประกอบคำนิยามชนิดแบบที่ซับซ้อน。องค์ประกอบของชนิดแบบที่ซับซ้อนคือองค์ประกอบ XML ที่มีองค์ประกอบและ/หรือรายละเอียดอื่น ๆ。

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

จำนวนการปรากฏ ไม่จำกัดในโครงสร้าง;มีเพียงครั้งเดียวใน element。
parent element element、redefine、schema
เนื้อหา annotation、simpleContent、complexContent、group、all、choice、sequence、attribute、attributeGroup、anyAttribute

กฎระเบียบ

<complexType
id=ID 
name=NCName 
abstract=true|false 
mixed=true|false
block=(#all|list of (extension|restriction))
final=(#all|list of (extension|restriction))
attributes
>
(annotation?,(simpleContent|complexContent|((group|all| 
choice|sequence)?,((attribute|attributeGroup)*,anyAttribute?))))
</complexType>

(? สัญญาณการประกาศอยู่ใน element complexType สามารถปรากฏขึ้นหรือไม่ได้ * สัญญาณการประกาศสามารถปรากฏขึ้นหรือไม่ได้หลายครั้ง。)

attribute

id

ตัวเลือก。กำหนด ID ที่เป็นสิ่งเดียวของ element。

name

ตัวเลือก。กำหนดชื่อของ element。

abstract

ตัวเลือก。กำหนดว่าควรอนุญาตให้ใช้ประเภท complex type ในเอกสารตัวอย่าง ถ้าค่านี้เป็น true แล้ว element ไม่สามารถใช้ประเภท complex type ตรงๆ แต่ต้องใช้ประเภท complex type ที่พัฒนามาจาก complex type นี้ ค่าเริ่มต้นคือ false。

mixed

ตัวเลือก。กำหนดว่าควรอนุญาตให้ข้อมูลแสดงตัวประกอบปรากฏระหว่าง element ลูกของประเภท complex type นี้หรือไม่ ค่าเริ่มต้นคือ false。

  • ถ้า element simpleContent คือ element ลูก,ไม่อนุญาต attribute mixed。
  • ถ้า element complexContent คือ element ลูก,th.removeAttribute จะสามารถเข้าใช้งาน mixed attribute ของ element complexContent ซึ่งเป็น attribute mixed ของ element complexContent。

block

ตัวเลือก。ป้องกันไม่ให้ประเภท complex type ที่มีประเภทพัฒนาเฉพาะถูกใช้แทนประเภท complex type ตัวนี้。ค่านี้สามารถมี #all หรือรายการที่เป็นชุดรวมของ extension หรือ restriction:

  • extension - ป้องกันไม่ให้ประเภทที่พัฒนามาจาก complex type นี้ถูกใช้แทนประเภท complex type ตัวนี้。
  • จำกัด - ป้องกันไม่ให้ประเภทที่พัฒนามาจาก complex type นี้ถูกใช้แทนประเภท complex type ตัวนี้。
  • #all - ป้องกันการใช้ชนิดฝากทั้งหมดที่สืบทอดมาแทนชนิดฝากนี้

final

ตัวเลือกต่าง ๆ กำหนดป้องกันการสืบทอดชนิดที่กำหนดโดย complexType นี้ ค่านี้สามารถมี #all หรือรายการที่ประกอบด้วย extension หรือ restriction

  • extension - ป้องกันการสืบทอดทางด้าน extension
  • restriction - ป้องกันการสืบทอดทางด้าน restriction
  • #all - ป้องกันการสืบทอดทั้งหมด (extension และ restriction)

attributes

ตัวเลือกต่าง ๆ กำหนดลูกฟังก์ชันขององค์ประกอบที่มีชื่อชิ้นแบบ non-schema ใดๆ

ตัวอย่าง

ตัวอย่าง 1

ในตัวอย่างด้านล่างนี้ มีองค์ประกอบฝากแบบ "note":

<xs:element name="note">
    <xs:complexType>
      <xs:sequence>
	<xs:element name="to" type="xs:string"/>
	<xs:element name="from" type="xs:string"/>
	<xs:element name="heading" type="xs:string"/>
	<xs:element name="body" type="xs:string"/>
      </xs:sequence>
    </xs:complexType>
</xs:element>

ตัวอย่าง 2

ในตัวอย่างด้านล่างนี้ มีชนิดฝากแบบ "fullpersoninfo" ที่ขยายชนิดที่สืบทอดมาจาก "personinfo" โดยใช้สามองค์ประกอบเสริม (address, city และ country):

<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>

ในตัวอย่างที่อยู่ด้านบน องค์ประกอบ "employee" ด้านบนจะต้องมีองค์ประกอบด้านล่างในลำดับที่นี้: "firstname", "lastname", "address", "city" และ "country"。