एक्सएमएल स्कीमा विशेषता तत्व
❮ पूर्ण XML स्कीमा संदर्भ
परिभाषा और उपयोग
विशेषता तत्व एक विशेषता को परिभाषित करता है।
तत्व जानकारी
- मूल तत्व: विशेषता समूह, स्कीमा, जटिल प्रकार, प्रतिबंध (सरल सामग्री और जटिल सामग्री दोनों), विस्तार (सरल सामग्री और जटिल सामग्री दोनों)
वाक्य - विन्यास
<attribute
default=string
fixed=string
form=qualified|unqualified
id=ID
name=NCName
ref=QName
type=QName
use=optional|prohibited|required
any attributes
>
(annotation?,(simpleType?))
</attribute>
(? चिन्ह यह घोषणा करता है कि तत्व शून्य या एक बार विशेषता तत्व के अंदर हो सकता है)
Attribute | Description |
---|---|
default | Optional. Specifies a default value for the attribute. Default and fixed attributes cannot both be present |
fixed | Optional. Specifies a fixed value for the attribute. Default and fixed attributes cannot both be present |
form | Optional. Specifies the form for the attribute. The default value is
the value of the attributeFormDefault attribute of the element
containing the attribute. Can be set to one of the following:
|
id | Optional. Specifies a unique ID for the element |
name | Optional. Specifies the name of the attribute. Name and ref attributes cannot both be present |
ref | Optional. Specifies a reference to a named attribute. Name and ref attributes cannot both be present. If ref is present, simpleType element, form, and type cannot be present |
type | Optional. Specifies a built-in data type or a simple type. The type attribute can only be present when the content does not contain a simpleType element |
use | Optional. Specifies how the attribute is used. Can be one
of the following values:
|
any attributes | Optional. Specifies any other attributes with non-schema namespace |
उदाहरण 1
<xs:attribute name="code">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z][A-Z]"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
ऊपर दिया गया उदाहरण इंगित करता है कि "कोड" विशेषता पर प्रतिबंध है। केवल स्वीकार्य मान a से z तक के दो बड़े अक्षर हैं।
उदाहरण 2
एक जटिल प्रकार के भीतर मौजूदा विशेषता परिभाषा का उपयोग करके एक विशेषता घोषित करने के लिए, रेफरी विशेषता का उपयोग करें:
<xs:attribute name="code">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z][A-Z]"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:complexType name="someComplexType">
<xs:attribute ref="code"/>
</xs:complexType>
उदाहरण 3
विशेषताओं में या तो एक डिफ़ॉल्ट मान या एक निश्चित मान निर्दिष्ट हो सकता है। जब कोई अन्य मान निर्दिष्ट नहीं किया जाता है तो एक डिफ़ॉल्ट मान स्वचालित रूप से विशेषता को असाइन किया जाता है। निम्नलिखित उदाहरण में डिफ़ॉल्ट मान "EN" है:
<xs:attribute name="lang" type="xs:string" default="EN"/>
जब कोई अन्य मान निर्दिष्ट नहीं किया जाता है तो एक निश्चित मान स्वचालित रूप से विशेषता को असाइन किया जाता है। लेकिन डिफ़ॉल्ट मानों के विपरीत; यदि आप निश्चित से कोई अन्य मान निर्दिष्ट करते हैं, तो दस्तावेज़ को अमान्य माना जाता है। निम्नलिखित उदाहरण में निश्चित मान "EN" है:
<xs:attribute name="lang" type="xs:string" fixed="EN"/>
उदाहरण 4
सभी विशेषताएँ डिफ़ॉल्ट रूप से वैकल्पिक हैं। यह स्पष्ट रूप से निर्दिष्ट करने के लिए कि विशेषता वैकल्पिक है, "उपयोग" विशेषता का उपयोग करें:
<xs:attribute name="lang" type="xs:string" use="optional"/>
आवश्यक विशेषता बनाने के लिए:
<xs:attribute name="lang" type="xs:string" use="required"/>
❮ पूर्ण XML स्कीमा संदर्भ