XML Schema attribute ਘਟਨਾ
ਨਿਰਧਾਰਣ ਅਤੇ ਵਰਤੋਂ
attribute ਘਟਨਾ ਇੱਕ ਗੁਣ ਨੂੰ ਨਿਰਧਾਰਿਤ ਕਰਦਾ ਹੈ。
ਘਟਨਾ ਸੂਚਨਾ
ਸਾਰਣਾ | schema ਘਟਨਾ ਵਿੱਚ ਇੱਕ ਵਾਰ ਨਿਰਧਾਰਿਤ ਕੀਤਾ ਜਾਂਦਾ ਹੈ। ਜਟਿਲ ਤਰੀਕੇ ਜਾਂ ਐਟਰੀਬਿਊਟ ਗਰੁੱਪ ਵਿੱਚ ਬਾਰ-ਬਾਰ ਹਵਾਲਾ ਦਿੱਤਾ ਜਾਂਦਾ ਹੈ。 |
ਮੂਲ ਘਟਨਾ | attributeGroup、schema、complexType、restriction (simpleContent)、extension (simpleContent)、restriction (complexContent)、extension (complexContent) |
ਸਮੱਗਰੀ | annotation、simpleType |
ਸ਼ਾਸਤਰ
<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>
(? ਚਿੰਨ੍ਹ ਇਹ ਘਟਨਾ ਨੂੰ ਐਟਰੀਬਿਊਟ ਘਟਨਾ ਵਿੱਚ ਕੋਈ ਵੀ ਸਮਾਂ ਜਾਂ ਇੱਕ ਵਾਰ ਪ੍ਰਯੋਗ ਕਰਨ ਦਾ ਅਧਿਕਾਰ ਦਿੰਦਾ ਹੈ。)
ਗੁਣ
default
ਵਿਕਲਪੀ। ਗੁਣ ਦੇ ਮੂਲਤਬੀ ਮੁੱਲ ਨੂੰ ਨਿਰਧਾਰਿਤ ਕਰਦਾ ਹੈ। default ਅਤੇ fixed ਗੁਣ ਨਹੀਂ ਸਾਂਝੇ ਹੋ ਸਕਦੇ。
fixed
ਵਿਕਲਪੀ। ਗੁਣ ਦੇ ਨਿਸ਼ਚਿਤ ਮੁੱਲ ਨੂੰ ਨਿਰਧਾਰਿਤ ਕਰਦਾ ਹੈ। default ਅਤੇ fixed ਗੁਣ ਨਹੀਂ ਸਾਂਝੇ ਹੋ ਸਕਦੇ。
form
ਵਿਕਲਪੀ। ਗੁਣ ਦੇ ਫਾਰਮੈਟ ਨੂੰ ਨਿਰਧਾਰਿਤ ਕਰਦਾ ਹੈ। ਮੂਲਤਬੀ ਮੁੱਲ ਹੈ ਕਿ ਸਕੇਮਾ ਮੌਲਿਕ ਤੱਤ ਦੇ attributeFormDefault ਗੁਣ ਦਾ ਮੁੱਲ। ਨਿਮਨਲਿਖਤ ਮੁੱਲਾਂ ਵਿੱਚੋਂ ਇੱਕ ਨੂੰ ਸੈਟ ਕੀਤਾ ਜਾ ਸਕਦਾ ਹੈ:
- qualified - ਸੂਚਿਤ ਕਰਦਾ ਹੈ ਕਿ ਇਹ ਗੁਣ ਨਾਮ ਸਪੇਸ ਪ੍ਰੋਫ਼ਿਕਸ ਅਤੇ ਇਸ ਗੁਣ ਦੇ ਬੇਕੋਰਸ ਨਾਮ (NCName) ਦੇ ਜ਼ਰੀਏ ਸੀਮਤ ਕੀਤਾ ਜਾਣਾ ਹੈ。
- "unqualified" - 指示此属性无须由命名空间前缀限定,且无须匹配此属性的无冒号名称 (NCName),即本地名称。
id
可选。规定该元素的唯一的 ID。
name
可选。规定属性的名称。name 和 ref 属性不能同时出现。
ref
可选。规定对指定的属性的引用。name 和 ref 属性不能同时出现。如果 ref 出现,则 simpleType 元素、form 和 type 不能出现。
type
可选。规定内建的数据类型或简单类型。type 属性只能在内容不包含 simpleType 元素时出现。
use
可选。规定如何使用该属性。可设置下面的值:
- optional - 属性是可选的并且可以具有任何值(默认)。
- prohibited - 不能使用属性。
- required - 属性的必需的。
any attributes
可选。规定带有 non-schema 命名空间的任何其他属性。
实例
例子 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>
上面的例子指示 "code" 属性有一个限定。唯一可接受的值是大写字母 A 到 Z 中的两个字母。
ਉਦਾਹਰਣ 2
ਜੇਕਰ ਤੁਸੀਂ ਕਿਸੇ ਜਟਿਲ ਤਰੀਕੇ ਵਿੱਚ ਇੱਕ ਪਹਿਲਾਂ ਤੋਂ ਹੋਏ ਲੱਗਦੇ ਮੁੱਲ ਨੂੰ ਦੁਹਰਾਉਣਾ ਚਾਹੁੰਦੇ ਹੋ, ਤਾਂ ref ਲੱਕੜੀ ਵਰਤੋਂ ਕਰੋ:
<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
ਸਾਰੇ ਗੁਣ ਮੂਲਤਬੀ ਚੋਣਵੇਂ ਹਨ।ਗੁਣ ਨੂੰ ਚੋਣਵੇਂ ਗੁਣ ਬਣਾਉਣ ਲਈ "use" ਗੁਣ ਵਰਤੋਂ ਕਰੋ:
<xs:attribute name="lang" type="xs:string" use="optional"/>
ਗੁਣ ਨੂੰ ਲਾਜ਼ਮੀ ਗੁਣ ਬਣਾਓ:
<xs:attribute name="lang" type="xs:string" use="required"/>