XML Şeması özniteliği Öğe
❮ Eksiksiz XML Şeması Referansı
Tanım ve Kullanım
Öznitelik öğesi bir özniteliği tanımlar.
Eleman Bilgileri
- Ana öğeler: featureGroup, schema, ComplexType, kısıtlama (hem simpleContent hem de ComplexContent), uzantı (hem simpleContent hem de ComplexContent)
Sözdizimi
<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>
(? işareti, öğenin öznitelik öğesi içinde sıfır veya bir kez oluşabileceğini bildirir)
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 |
örnek 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>
Yukarıdaki örnek, "kod" özniteliğinin bir kısıtlaması olduğunu gösterir. Kabul edilebilir tek değer, a'dan z'ye iki büyük harftir.
Örnek 2
Karmaşık bir tür içinde mevcut bir öznitelik tanımını kullanarak bir özniteliği bildirmek için ref özniteliğini kullanın:
<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>
Örnek 3
Nitelikler, varsayılan bir değere VEYA belirtilen sabit bir değere sahip olabilir. Başka bir değer belirtilmediğinde, özniteliğe otomatik olarak varsayılan bir değer atanır. Aşağıdaki örnekte varsayılan değer "EN"dir:
<xs:attribute name="lang" type="xs:string" default="EN"/>
Başka bir değer belirtilmediğinde de özniteliğe otomatik olarak sabit bir değer atanır. Ancak varsayılan değerlerden farklı olarak; sabit değerden başka bir değer belirtirseniz, belge geçersiz sayılır. Aşağıdaki örnekte sabit değer "EN"dir:
<xs:attribute name="lang" type="xs:string" fixed="EN"/>
Örnek 4
Tüm nitelikler varsayılan olarak isteğe bağlıdır. Niteliğin isteğe bağlı olduğunu açıkça belirtmek için "use" niteliğini kullanın:
<xs:attribute name="lang" type="xs:string" use="optional"/>
Bir özniteliği gerekli kılmak için:
<xs:attribute name="lang" type="xs:string" use="required"/>
❮ Eksiksiz XML Şeması Referansı