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>
(? 기호는 요소가 속성 요소 내에서 0번 또는 1번 발생할 수 있음을 선언합니다.)
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개입니다.
실시예 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 스키마 참조