Game Development Reference
In-Depth Information
<xs:element name="CharacterData">
<xs:complexType>
<xs:sequence>
<xs:element name="Character" type="xs:string"
minOccurs="0" />
<xs:element name="Description" type="xs:string"
minOccurs="0" />
<xs:element name="HitPoints" type="xs:string"
minOccurs="0" />
<xs:element name="MoveSpeed" type="xs:string"
minOccurs="0" />
<xs:element name="AttackPower" type="xs:string"
minOccurs="0" />
<xs:element name="Class" type="xs:string"
minOccurs="0" />
<xs:element name="Thumbnail" type="xs:string"
minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
Listing 12.11.
XSD for xformed.xml (xformed.xsd).
If we were to use this XSD directly to generate the class definition, then all of
the field types would be of type
string
due to the
xs:string
type in the XSD.
Let's modify the XSD and provide the correct types (see Listing 12.12).
<?xml version="1.0" standalone="yes"?>
<xs:schema id="Characters" xmlns="" xmlns:xs="
http://www.w3.org
/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Characters" msdata:IsDataSet="true"
msdata:Locale="en-US">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="CharacterData">
<xs:complexType>
<xs:sequence>
<xs:element name="Character" type="xs:string"
minOccurs="0" />
<xs:element name="Description" type="xs:string"
minOccurs="0" />
<xs:element name="HitPoints" type="xs:float"
minOccurs="1" />
<xs:element name="MoveSpeed" type="xs:float"
minOccurs="1" />
<xs:element name="AttackPower" type="xs:float"
minOccurs="1" />
<xs:element name="Class" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Standard" />
<xs:enumeration value="Armored" />