XML Skema kenmerk Element
❮ Voltooi XML-skemaverwysing
Definisie en gebruik
Die kenmerkelement definieer 'n kenmerk.
Elementinligting
- Ouer-elemente: kenmerkGroep, skema, kompleksTipe, beperking (beide eenvoudigeInhoud en komplekseInhoud), uitbreiding (beide eenvoudigInhoud en komplekseInhoud)
Sintaksis
<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>
(Die ? teken verklaar dat die element nul of een keer binne die kenmerkelement kan voorkom)
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 |
Voorbeeld 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>
Die voorbeeld hierbo dui aan dat die "code"-kenmerk 'n beperking het. Die enigste aanvaarbare waarde is twee van die hoofletters van a tot z.
Voorbeeld 2
Om 'n kenmerk te verklaar deur 'n bestaande kenmerkdefinisie binne 'n komplekse tipe te gebruik, gebruik die ref-kenmerk:
<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>
Voorbeeld 3
Eienskappe kan óf 'n verstekwaarde OF 'n vaste waarde gespesifiseer hê. 'n Standaardwaarde word outomaties aan die kenmerk toegeken wanneer geen ander waarde gespesifiseer word nie. In die volgende voorbeeld is die verstekwaarde "EN":
<xs:attribute name="lang" type="xs:string" default="EN"/>
'n Vaste waarde word ook outomaties aan die kenmerk toegeken wanneer geen ander waarde gespesifiseer word nie. Maar anders as verstekwaardes; as jy 'n ander waarde as die vaste spesifiseer, word die dokument as ongeldig beskou. In die volgende voorbeeld is die vaste waarde "EN":
<xs:attribute name="lang" type="xs:string" fixed="EN"/>
Voorbeeld 4
Alle eienskappe is by verstek opsioneel. Om uitdruklik te spesifiseer dat die kenmerk opsioneel is, gebruik die "use"-kenmerk:
<xs:attribute name="lang" type="xs:string" use="optional"/>
Om 'n kenmerk vereis te maak:
<xs:attribute name="lang" type="xs:string" use="required"/>
❮ Voltooi XML-skemaverwysing