एक्सएसडी <anyAttribute> तत्व
<anyAttribute> तत्व हमें स्कीमा द्वारा निर्दिष्ट नहीं किए गए विशेषताओं के साथ XML दस्तावेज़ का विस्तार करने में सक्षम बनाता है!
<anyAttribute> तत्व
<anyAttribute> तत्व हमें स्कीमा द्वारा निर्दिष्ट नहीं किए गए विशेषताओं के साथ XML दस्तावेज़ का विस्तार करने में सक्षम बनाता है।
निम्न उदाहरण "family.xsd" नामक XML स्कीमा का एक अंश है। यह "व्यक्ति" तत्व के लिए एक घोषणा दिखाता है। <anyAttribute> तत्व का उपयोग करके हम "व्यक्ति" तत्व में कितनी भी विशेषताएँ जोड़ सकते हैं:
<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>
अब हम "व्यक्ति" तत्व को "आईकलर" विशेषता के साथ विस्तारित करना चाहते हैं। इस मामले में हम ऐसा कर सकते हैं, भले ही उपरोक्त स्कीमा के लेखक ने कभी भी "आईकलर" विशेषता घोषित नहीं की हो।
इस स्कीमा फ़ाइल को देखें, जिसे "attribute.xsd" कहा जाता है:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="https://www.w3schools.com"
xmlns="https://www.w3schools.com"
elementFormDefault="qualified">
<xs:attribute name="eyecolor">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="blue|brown|green|grey"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:schema>
नीचे दी गई एक्सएमएल फ़ाइल (जिसे "माईफ़ैमिली.एक्सएमएल" कहा जाता है), दो अलग-अलग स्कीमाओं के घटकों का उपयोग करती है; "family.xsd" और "attribute.xsd":
<?xml version="1.0" encoding="UTF-8"?>
<persons xmlns="http://www.microsoft.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:SchemaLocation="http://www.microsoft.com family.xsd
https://www.w3schools.com attribute.xsd">
<person eyecolor="green">
<firstname>Hege</firstname>
<lastname>Refsnes</lastname>
</person>
<person eyecolor="blue">
<firstname>Stale</firstname>
<lastname>Refsnes</lastname>
</person>
</persons>
उपरोक्त XML फ़ाइल मान्य है क्योंकि स्कीमा "family.xsd" हमें "व्यक्ति" तत्व में एक विशेषता जोड़ने की अनुमति देती है।
विस्तृत दस्तावेज़ बनाने के लिए <any> और <anyAttribute> तत्वों का उपयोग किया जाता है! वे दस्तावेज़ों को अतिरिक्त तत्वों को शामिल करने की अनुमति देते हैं जो मुख्य XML स्कीमा में घोषित नहीं किए गए हैं।