XML Tutorial

XML หน้าแรก บทนำ XML XML วิธีใช้งาน XML Tree ไวยากรณ์ XML องค์ประกอบ XML คุณสมบัติ XML XML เนมสเปซ จอแสดงผล XML XML HttpRequest XML Parser XML DOM XML XPath XML XSLT XML XQuery XML XLink เครื่องมือตรวจสอบ XML XML DTD XML Schema XML Server ตัวอย่าง XML แบบทดสอบ XML ใบรับรอง XML

XML AJAX

บทนำ AJAX AJAX XMLHttp คำขอ AJAX การตอบสนอง AJAX ไฟล์ AJAX XML AJAX PHP AJAX ASP ฐานข้อมูล AJAX แอปพลิเคชัน AJAX ตัวอย่าง AJAX

XML DOM

บทนำ DOM โหนด DOM การเข้าถึง DOM ข้อมูลโหนด DOM รายการโหนด DOM DOM Traversing การนำทาง DOM DOM รับค่า DOM เปลี่ยนโหนด DOM ลบโหนด DOM แทนที่โหนด DOM สร้างโหนด DOM เพิ่มโหนด DOM โคลนโหนด ตัวอย่าง DOM

บทช่วย สอนXPath

บทนำ XPath โหนด XPath ไวยากรณ์ XPath แกน XPath ตัวดำเนินการ XPath ตัวอย่าง XPath

กวดวิชาXSLT

บทนำ XSLT ภาษา XSL การแปลง XSLT XSLT <แม่แบบ> XSLT <ค่าของ> XSLT <for-each> XSLT <sort> XSLT <if> XSLT <เลือก> ใช้ XSLT XSLT บนไคลเอนต์ XSLT บนเซิร์ฟเวอร์ XSLT แก้ไข XML ตัวอย่าง XSLT

กวดวิชาXQuery

บทนำ XQuery ตัวอย่าง XQuery XQuery FLWOR XQuery HTML ข้อกำหนด XQuery ไวยากรณ์ XQuery XQuery เพิ่ม XQuery Select ฟังก์ชัน XQuery

XML DTD

บทนำ DTD บล็อกตัวต่อ DTD องค์ประกอบ DTD คุณสมบัติ DTD องค์ประกอบ DTD เทียบกับ Attr หน่วยงาน DTD ตัวอย่าง DTD

ส คีมา XSD

บทนำ XSD XSD วิธีการ XSD <schema> องค์ประกอบ XSD แอตทริบิวต์ XSD ข้อจำกัด XSD

XSD Complex

องค์ประกอบ XSD XSD ว่างเปล่า องค์ประกอบ XSD เท่านั้น XSD Text เท่านั้น XSD ผสม ตัวชี้วัด XSD XSD <ใด ๆ> XSD <anyAttribute> การทดแทน XSD XSD ตัวอย่าง

ข้อมูลXSD

XSD สตริง วันที่ XSD XSD ตัวเลข XSD เบ็ดเตล็ด ข้อมูลอ้างอิง XSD

บริการเว็บ

XML Services XML WSDL XML SOAP XML RDF XML RSS

อ้างอิง

ประเภทโหนด DOM โหนด DOM DOM NodeList DOM NamedNodeMap เอกสาร DOM องค์ประกอบ DOM แอตทริบิวต์ DOM ข้อความ DOM DOM CDATA ความคิดเห็นของ DOM DOM XMLHttpRequest DOM Parser องค์ประกอบ XSLT ฟังก์ชัน XSLT/XPath

องค์ประกอบแอตทริบิวต์ XML Schema


❮ การอ้างอิงสคีมา XML ที่สมบูรณ์

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

องค์ประกอบแอตทริบิวต์กำหนดแอตทริบิวต์

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

  • องค์ประกอบหลัก: attributeGroup, schema, complexType, ข้อจำกัด (ทั้ง simpleContent และ complexContent), ส่วนขยาย (ทั้ง simpleContent และ complexContent)

ไวยากรณ์

<attribute
default=string
fixed=string
form=qualified|unqualified
id=ID
name=NCName
ref=QName
type=QName
use=optional|prohibited|required
any attributes
>

(annotation?,(simpleType?))

</attribute>

(เครื่องหมาย ? ประกาศว่าองค์ประกอบสามารถเกิดขึ้นได้เป็นศูนย์หรือครั้งเดียวภายในองค์ประกอบแอตทริบิวต์)

Attribute Description
default Optional. Specifies a default value for the attribute. Default and fixed attributes cannot both be present
fixed Optional. Specifies a fixed value for the attribute. Default and fixed attributes cannot both be present
form Optional. Specifies the form for the attribute. The default value is the value of the attributeFormDefault attribute of the element containing the attribute. Can be set to one of the following:
  • "qualified" - indicates that this attribute must be qualified with the namespace prefix and the no-colon-name (NCName) of the attribute
  • unqualified - indicates that this attribute is not required to be qualified with the namespace prefix and is matched against the (NCName) of the attribute
id Optional. Specifies a unique ID for the element
name Optional. Specifies the name of the attribute. Name and ref attributes cannot both be present
ref Optional. Specifies a reference to a named attribute. Name and ref attributes cannot both be present. If ref is present, simpleType element, form, and type cannot be present
type Optional. Specifies a built-in data type or a simple type. The type attribute can only be present when the content does not contain a simpleType element
use Optional. Specifies how the attribute is used. Can be one of the following values:
  • optional - the attribute is optional (this is default)
  • prohibited - the attribute cannot be used
  • required - the attribute is required
any attributes Optional. Specifies any other attributes with non-schema namespace

ตัวอย่าง 1

<xs:attribute name="code">

<xs:simpleType>
  <xs:restriction base="xs:string">
    <xs:pattern value="[A-Z][A-Z]"/>
  </xs:restriction>
</xs:simpleType>

</xs:attribute>

ตัวอย่างข้างต้นระบุว่าแอตทริบิวต์ "code" มีข้อจำกัด ค่าเดียวที่ยอมรับได้คืออักษรตัวพิมพ์ใหญ่สองตัวจาก a ถึง z

ตัวอย่าง 2

หากต้องการประกาศแอตทริบิวต์โดยใช้คำจำกัดความแอตทริบิวต์ที่มีอยู่ภายในประเภทที่ซับซ้อน ให้ใช้แอตทริบิวต์ ref:

<xs:attribute name="code">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="[A-Z][A-Z]"/>
    </xs:restriction>
  </xs:simpleType>
</xs:attribute>

<xs:complexType name="someComplexType">
  <xs:attribute ref="code"/>
</xs:complexType>

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

แอตทริบิวต์สามารถมีได้ทั้งค่าเริ่มต้นหรือค่าคงที่ที่ระบุ ค่าเริ่มต้นจะถูกกำหนดให้กับแอตทริบิวต์โดยอัตโนมัติเมื่อไม่ได้ระบุค่าอื่น ในตัวอย่างต่อไปนี้ ค่าเริ่มต้นคือ "EN":

<xs:attribute name="lang" type="xs:string" default="EN"/>

ค่าคงที่ยังถูกกำหนดให้กับแอตทริบิวต์โดยอัตโนมัติเมื่อไม่ได้ระบุค่าอื่น แต่ต่างจากค่าเริ่มต้น หากคุณระบุค่าอื่นที่ไม่ใช่ค่าคงที่ เอกสารจะถือว่าไม่ถูกต้อง ในตัวอย่างต่อไปนี้ ค่าคงที่คือ "EN":

<xs:attribute name="lang" type="xs:string" fixed="EN"/>

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

แอตทริบิวต์ทั้งหมดเป็นทางเลือกโดยค่าเริ่มต้น หากต้องการระบุอย่างชัดเจนว่าแอตทริบิวต์เป็นทางเลือก ให้ใช้แอตทริบิวต์ "use":

<xs:attribute name="lang" type="xs:string" use="optional"/>

ในการสร้างแอตทริบิวต์ที่จำเป็น:

<xs:attribute name="lang" type="xs:string" use="required"/>

❮ การอ้างอิงสคีมา XML ที่สมบูรณ์