Attribute Declarations
To make the fullName
element more informative, it would be nice to add a language
attribute to provide a hint as to how it should be pronounced.
Although adding an attribute to an element sounds like a fairly
simple task, it is complicated by the fact that elements with simple
types (like xs:string) cannot
have attribute values.
Attributes are declared using the xs:attribute element. Attributes may be declared globally by
top-level xs:attribute elements
(which may be referenced from anywhere within the schema) or locally
as part of a complex type definition that is associated with a
particular element.
To incorporate a language
attribute into the fullName
element declaration, a new complex type based on the built-in
xs:string type must be created.
To do this, three new schema elements must be used: xs:complexType , xs:simpleContent,
and xs:extension:
<xs:element name="fullName">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="language" type="xs:language"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>This declaration no longer has a type attribute. Instead, it has an
xs:complexType child element.
This element tells the schema processor that the fullName element may have attributes, but
the xs:simpleContent element
tells the processor that the content of the element is a simple
type. To specify what type of simple content, it uses the base attribute of the xs:extension element to
derive a new ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access