XSD Text-Only Elements
องค์ประกอบแบบข้อความเท่านั้นที่ซับซ้อนสามารถมีข้อความและแอตทริบิวต์ได้
องค์ประกอบเฉพาะข้อความที่ซับซ้อน
ประเภทนี้มีเพียงเนื้อหาธรรมดา (ข้อความและแอตทริบิวต์) ดังนั้นเราจึงเพิ่มองค์ประกอบ simpleContent รอบเนื้อหา เมื่อใช้เนื้อหาอย่างง่าย คุณต้องกำหนดส่วนขยายหรือข้อจำกัดภายในองค์ประกอบ simpleContent เช่นนี้
<xs:element name="somename">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="basetype">
....
....
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
OR
<xs:element name="somename">
<xs:complexType>
<xs:simpleContent>
<xs:restriction base="basetype">
....
....
</xs:restriction>
</xs:simpleContent>
</xs:complexType>
</xs:element>
เคล็ดลับ:ใช้องค์ประกอบส่วนขยาย/การจำกัดเพื่อขยายหรือจำกัดประเภทพื้นฐานอย่างง่ายสำหรับองค์ประกอบ
นี่คือตัวอย่างขององค์ประกอบ XML "shoesize" ที่มีข้อความเท่านั้น:
<shoesize country="france">35</shoesize>
ตัวอย่างต่อไปนี้จะประกาศ complexType "shoesize" เนื้อหาถูกกำหนดเป็นค่าจำนวนเต็ม และองค์ประกอบ "ขนาดรองเท้า" ยังมีแอตทริบิวต์ชื่อ "ประเทศ" ด้วย:
<xs:element name="shoesize">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:integer">
<xs:attribute name="country" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
นอกจากนี้เรายังสามารถตั้งชื่อองค์ประกอบ complexType และให้องค์ประกอบ "shoesize" มีแอตทริบิวต์ประเภทที่อ้างอิงถึงชื่อของ complexType (หากคุณใช้วิธีนี้ องค์ประกอบหลายอย่างสามารถอ้างถึงประเภทที่ซับซ้อนเดียวกันได้):
<xs:element name="shoesize" type="shoetype"/>
<xs:complexType name="shoetype">
<xs:simpleContent>
<xs:extension base="xs:integer">
<xs:attribute name="country" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>