XSD element substitution (Element Substitution)
- Previous page XSD <anyAttribute>
- Next page XSD instance
ຜ່ານ XML Schema, ສະຖານະບັນໜຶ່ງສາມາດປ່ຽນສະຖານະບັນອື່ນອີກ.
ການປ່ຽນສະຖານະບັນ
ພວກເຮົາຈະເວົ້າກ່ຽວກັບຄວາມຈະເປັນຫນັງກ່າວໄວ້ທີ່ພວກເຮົາຈະນັບຄົນອານຸສາວອັງກິດແລະເນເຊຍ. ພວກເຮົາຫວັງວ່າຈະມີຄວາມສາມາດໃຫ້ຜູ້ນຳໃຊ້ເລືອກຊື່ສັບສາຍໃນເອກະສານ XML ທີ່ໃຊ້ພາສານໍຣາວຫຼືພາສາອັງກິດ.
ເພື່ອແກ້ໄຂບັນຫານີ້ ພວກເຮົາສາມາດກໍານົດໃນ XML schema: substitutionGroupເພື່ອກ່າວແບບຈະເປັນຫນັງກ່າວໄວ້ທີ່ພວກເຮົາກໍານົດຫນັກສັບຫຼັກສາຍທີ່ຫນັກສັບທີ່ສາມາດແທນຫນັກສັບຫຼັກສາຍນັ້ນ.
<xs:element name="name" type="xs:string"/> <xs:element name="navn" substitutionGroup="name"/>
ໃນຄວາມຈະເປັນຫນັງກ່າວໄວ້ຂອງພາຍໃນຫນັງກ່າວໄວ້ "name" ເປັນຫນັກສັບຫຼັກ ແລະ "navn" ສາມາດແທນ "name" ໄດ້.
ບັນຈຸບາງສາຍຂອງ XML schema:
<xs:element name="name" type="xs:string"/> <xs:element name="navn" substitutionGroup="name"/> <xs:complexType name="custinfo"> <xs:sequence> <xs:element ref="name"/> </xs:sequence> </xs:complexType> <xs:element name="customer" type="custinfo"/> <xs:element name="kunde" substitutionGroup="customer"/>
ເອກະສານ XML ທີ່ຖືກກົດຫມາຍຄືກັນ (ອີງຕາມ schema ໃນປີກາຍ):
<customer> <name>John Smith</name> </customer>
ຫຼືຄືກັນນັ້ນ:
<kunde> <navn>John Smith</navn> </kunde>
ປ້ອງກັນການແທນບັນດາຫຼັກສັບ
ເພື່ອປ້ອງກັນອີກຫຼັກສັບອື່ນທີ່ຈະແທນບັນດາຫຼັກສັບທີ່ກໍານົດໄວ້ຫນັງຢ່າງຫນັງນັ້ນແລ້ວ ຂ້ອຍຂໍໃຫ້ໃຊ້ປະເພດ block 属性:
<xs:element name="name" type="xs:string"> block="substitution"/>
ບັນຈຸບາງສາຍຂອງ XML schema:
<xs:element name="name" type="xs:string" block="substitution"/> <xs:element name="navn" substitutionGroup="name"/> <xs:complexType name="custinfo"> <xs:sequence> <xs:element ref="name"/> </xs:sequence> </xs:complexType> <xs:element name="customer" type="custinfo" block="substitution"/> <xs:element name="kunde" substitutionGroup="customer"/>
ເອກະສານ XML ທີ່ຖືກກົດຫມາຍຄືກັນ (ອີງຕາມ schema ໃນປີກາຍ):
<customer> <name>John Smith</name> </customer>
ບໍ່ມີຄວາມຖືກຕ້ອງອີກຕາມໂດຍເອກະສານດັ່ງກ່າວຫຼັງນັ້ນ:
<kunde> <navn>John Smith</navn> </kunde>
Using substitutionGroup
The type of substitutable elements must be the same as the primary element, or derived from the primary element. If the type of substitutable elements is the same as the type of the primary element, then you do not need to specify the type of substitutable elements.
Please note that all elements in substitutionGroup (primary elements and substitutable elements) must be declared as global elements, otherwise they will not work!
What are global elements (Global Elements)?
Global elements refer to the direct child elements of the "schema" element! Local elements (Local elements) refer to elements nested within other elements.
- Previous page XSD <anyAttribute>
- Next page XSD instance