XSD <anyAttribute> element
- Previous page XSD <any>
- Next page XSD element substitution
<anyAttribute> element ຈະເອົາພະລັງວັດຂອງພວກເຮົາເພື່ອຂະຫຍາຍ XML document ຜ່ານລັກສະນະທີ່ບໍ່ໄດ້ກໍານົດໃນ schema!
<anyAttribute> element
<anyAttribute> element ຈະເອົາພະລັງວັດຂອງພວກເຮົາເພື່ອຂະຫຍາຍ XML document ຜ່ານລັກສະນະທີ່ບໍ່ໄດ້ກໍານົດໃນ schema!
ບົດສະຫຼຸບນີ້ແມ່ນສິ່ງທີ່ມາຈາກ XML schema ຊື່ "family.xsd" ເຊິ່ງຈະສະແດງການຖະແຫຼງ "person" element. ຜ່ານການໃຊ້ <anyAttribute> element, ພວກເຮົາສາມາດເພີ່ມລັກສະນະຫຼາຍອັນໃຫ້ element "person":
<xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:sequence> <xs:anyAttribute/> </xs:complexType> </xs:element>
ປະຈຸບັນ ພວກເຮົາຫວັງຈະຂະຫຍາຍ element "person" ດ້ວຍ attribute "gender". ໃນກໍລະນີນີ້, ພວກເຮົາສາມາດດໍາເນີນການນັ້ນ, ເຖິງແມ່ນວ່າ ຜູ້ຂຽນ schema ບໍ່ໄດ້ປະກາດ attribute "gender" ມາກໍ່.
ບັນປະດາການ schema ດັ່ງກ່າວ ຊື່ "attribute.xsd":
<?xml version="1.0" encoding="ISO-8859-1"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.codew3c.com" xmlns="http://www.codew3c.com" elementFormDefault="qualified"> <xs:attribute name="gender"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="male|female"/> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:schema>
ດັ່ງກ່າວ XML (ຊື່ "Myfamily.xml") ທີ່ໃຊ້ສ່ວນປະກອບຈາກ schema ຕ່າງກັນ, "family.xsd" ແລະ "attribute.xsd":
<?xml version="1.0" encoding="ISO-8859-1"?> <persons xmlns="http://www.microsoft.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:SchemaLocation="http://www.microsoft.com family.xsd http://www.codew3c.com attribute.xsd"> <person gender="female"> <firstname>Jane</firstname> <lastname>Smith</lastname> </person> <person gender="male"> <firstname>David</firstname> <lastname>Smith</lastname> </person> </persons>
XML ຕົວແບບນີ້ມີຄວາມຖືກຕ້ອງ, ຍ້ອນ schema "family.xsd" ອະນຸຍາດໃຫ້ພວກເຮົາເພີ່ມຄວາມລວມໃຫ້ element "person".
<any> ແລະ <anyAttribute> ທັງສອງສາມາດນຳໃຊ້ເພື່ອສ້າງເນື້ອຫາຍທີ່ສາມາດກວມເອົາສິນລະປະພາບທີ່ບໍ່ໄດ້ຖືກຖະແຫຼງໃນ XML schema ທີ່ຫົວເປັນ. ນີ້ຈະເຮັດໃຫ້ເນື້ອຫາຍມີຄວາມສາມາດກວມເອົາສິນລະປະພາບອື່ນ.
- Previous page XSD <any>
- Next page XSD element substitution