एक्सएसडी <anyAttribute> एलीमेंट

<anyAttribute> एलीमेंट हमें XML दस्तावेज़ को शेड्यूल के नियमावल से निर्दिष्ट नहीं होने वाले अचरणों के द्वारा विस्तारित करने की क्षमता देता है!

<anyAttribute> एलीमेंट

<anyAttribute> एलीमेंट हमें XML दस्तावेज़ को शेड्यूल के नियमावल से निर्दिष्ट नहीं होने वाले अचरणों के द्वारा विस्तारित करने की क्षमता देता है!

इस उदाहरण "family.xsd" नामक XML शेड्यूल के एक टुकड़े से आया है। यह हमें "person" एलीमेंट के लिए एक घोषणा को दिखाता है। <anyAttribute> एलीमेंट का उपयोग करके हम "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> दोनों को विस्तारित दस्तावेज के निर्माण के लिए उपयोग किया जा सकता है! वे दस्तावेज को मुख्य एक्सएमएल शेमा में घोषित नहीं हुए अतिरिक्त एलीमेंट को समाविष्ट करने की क्षमता प्रदान करते हैं。