عنصر سمة مخطط XML
❮ مرجع مخطط XML الكامل
التعريف والاستخدام
يحدد عنصر السمة سمة.
معلومات العنصر
- العناصر الأصلية: attributeGroup ، schema ، complexType ، تقييد (كلاهما simpleContent و complexContent) ، الامتداد (كلاهما simpleContent و complexContent)
بناء الجملة
<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>
يشير المثال أعلاه إلى أن السمة "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"/>
❮ مرجع مخطط XML الكامل