O'Reilly logo

Java and SOAP by Robert Englander

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

3.3. Indicating Type

Every element that contains a value must also indicate the type of the data. There are a few different ways to indicate the data type. The first mechanism is to include an xsi:type attribute as part of the element. This means that the attribute is named type, as defined by the namespace indicated by xsi. The value assigned to xsi:type must be a valid type identifier such as xsd:float, xsd:string, etc. In the second mechanism, the value can be an element of an array that already constrains the type of its constituent parts to a particular data type. In this case, no explicit type declaration for the individual values is necessary; we'll see this later when we talk about arrays. Finally, the element name itself can be related to some type that can be determined by looking at the associated XML schema. The following extract from an XML schema defines a compound data type:

<element name="Automobile" type="Automobile"/>
<complexType name="Automobile">
     <element name="make" type="xsd:string"/>
     <element name="model" type="xsd:string"/>
     <element name="year" type="xsd:int"/>
</complexType>

The data type Automobile contains elements named make and model of type string, as well as a year of type int. Now let's look at an instance of type Automobile based on this schema:

<niceCar xsi:type="Automobile" >
    <model>Corvette</model>
<make>Chevrolet</make>
    <year>1999</year>
</niceCar>

This XML defines an instance of type Automobile: a 1999 Chevrolet Corvette. Because the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required