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

การกำหนดและการใช้งาน

complexType กำหนดองค์ประกอบที่ซับซ้อน。องค์ประกอบที่ซับซ้อนเป็นองค์ประกอบ XML ที่มีองค์ประกอบอื่นและ/หรืออุปกรณ์อื่นๆ。

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

จำนวนการเกิดขึ้น ในโครงสร้างเป็นอิสระ; ในองค์ประกอบเป็นครั้งเดียว。
เป็นองค์ประกอบพ่อ 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))
คุณสมบัติทั้งหมด
>
(annotation?,(simpleContent|complexContent|((group|all| 
choice|sequence)?,((attribute|attributeGroup)*,anyAttribute?))))
</complexType>

(? สัญญาณประกาศใน complexType อาจปรากฏเป็น 0 หรือ 1 ครั้ง,* สัญญาณประกาศให้ element อาจปรากฏเป็น 0 หรือมากกว่า 1 ครั้ง)

attribute

id

ใช้ได้เลือก กำหนด ID ที่เป็นเดียวที่สำหรับ element นี้

name

ใช้ได้เลือก กำหนดชื่อของ element

abstract

ใช้ได้เลือก กำหนดว่าสามารถใช้ complexType ในเอกสารตัวอย่างหรือไม่ ถ้าค่านี้เป็น true ตัวองค์ประกอบไม่สามารถใช้ complexType โดยตรง แต่ต้องใช้ complexType ที่ยืมออกมาจาก complexType นี้ ค่าเริ่มต้นคือ false

mixed

ใช้ได้เลือก กำหนดว่าสามารถมีข้อมูลของอักษรประกอบในช่องว่างระหว่าง element ลูกของ complexType หรือไม่ ค่าเริ่มต้นคือ false

  • ถ้า simpleContent มี element ย่อย มixed ไม่อนุญาต
  • ถ้า complexContent มี element ย่อย มixed นี้สามารถถูก overwrite โดย mixed ของ complexContent

block

ใช้ได้เลือก ป้องกันไม่ให้ชนิดที่ยืมออกมาจาก complexType ที่กำหนดใช้เป็นทางเลือกที่แทน complexType นี้ ค่านี้สามารถประกอบด้วย #all หรือรายการที่เป็นชุดย่อยของ extension หรือ restriction

  • extension - ป้องกันไม่ให้ชนิดที่ยืมออกมาจาก complexType ด้วยวิธี extension ใช้เป็นทางเลือกที่แทน complexType นี้
  • restriction - ป้องกันไม่ให้ชนิดที่ยืมออกมาจาก complexType ด้วยวิธี restriction ใช้เป็นทางเลือกที่แทน complexType นี้
  • #all - ป้องกันไม่ให้ชนิดที่ยืมออกมาจาก complexType ทั้งหมดใช้เป็นทางเลือกที่แทน complexType นี้

final

ใช้ได้เลือก ป้องกันไม่ให้จาก complexType นี้ยืมออกมาชนิดที่กำหนด ค่านี้สามารถประกอบด้วย #all หรือรายการที่เป็นชุดย่อยของ extension หรือ restriction

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

คุณสมบัติทั้งหมด

ตั้งแต่งเลือก กำหนดรูปแบบของคุณสมบัติที่มีชื่อเรียกที่ไม่ใช้มาตรฐาน

ตัวอย่าง

ตัวอย่าง 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" ที่ขยายชนิดที่สืบทอดมาโดยใช้สามองค์ประกอบเสริม (address, city และ country) โดยมีชนิดที่ซับซ้อน "personinfo" สืบทอดมา

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