Altova XMLSpy 2025 Enterprise Edition

Specifying the Type of an Element

Home Prev Top Next

The child elements of Address are those defined for the global complex type AddressType (the content model of which is defined in the XML Schema AddressLast.xsd shown in the Schema View screenshot below).

tut_18a

We would, however, like to use a specific US or UK address type rather than the generic address type. You will recall that, in the AddressLast.xsd schema, we created global complex types for US-Address and UK-Address by extending the AddressType complex type. The content model of US-Address is shown below.

us_address_type

In the XML document, in order to specify that the Address element must conform to one of the extended Address types (US-Address or UK-Address) rather than the generic AddressType, we must specify the required extended complex type as an attribute of the Address element.

 

We add this attribute of the Address element as follows:

 

1.In the XML document, right-click the Name element, and select Insert Before from the context menu (see screenshot below).

insert_attribute

2.A new element node named new_elem is added above the Name element (see screenshot below). Click the element type to the left of the node's name and, in the menu that appears (screenshot below), select the Attribute node type. The node type will be changed to the Attribute node type; however, the name is still new_elem.

tut_37bMod

3.Double-click the node name and, in the entry helper popup that appears, select xsi:type.

4.Press the Tab key to move to the attribute's value field. A popup menus containing the available xsi:type values is displayed (screenshot below). These values are the complex types that have been defined for the Address element in the schema.

TutXMLElemType04

5.Select US-Address as the value of the xsi:type attribute.

 

Note:The xsi: prefix allows you to use special XML Schema related commands in your XML document instance. Notice that the the namespace for the xsi: prefix was automatically added to the document element when you assigned a schema to your XML file. In the above case, you have specified a type for the Address element. See the XML Schema specification for more information.

 

 

© 2018-2024 Altova GmbH