XSD <anyAttribute> एलीमेंट
- पिछला पृष्ठ XSD <any>
- अगला पृष्ठ XSD एलीमेंट प्रतिस्थापन
元素
下面的例子是来自名为 "family.xsd" 的 XML schema 的一个片段。它为我们展示了针对 "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>
अब, हम "gender" अटीब्यूट के द्वारा "person" एलीमेंट को विस्तारित करना चाहते हैं। इस स्थिति में, हम ऐसा कर सकते हैं, भले ही schema के लेखक ने कभी भी कोई "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" हमें "person" एलीमेंट में गुण जोड़ने की अनुमति देता है。
<any> और <anyAttribute> दोनों को विस्तार्य दस्तावेज़ बनाने के लिए उपयोग किया जा सकता है! वे दस्तावेज़ को मुख्य XML शेमा में घोषित न किए गए अतिरिक्त एलीमेंट शामिल करने की क्षमता देते हैं。
- पिछला पृष्ठ XSD <any>
- अगला पृष्ठ XSD एलीमेंट प्रतिस्थापन