Java Reference
In-Depth Information
This is a straightforward complex element with attributes for the coordinate values, which are specified
as type
double
.
Defining a Text Element Type
The type for
<text/>
elements is the odd one out, but it's not difficult. It involves four child elements for
the color, the position, the font, and the text itself, plus an attribute to specify the angle. The type definition
is as follows:
<!--Type for a sketch text element -->
<xsd:complexType name="TextType">
<xsd:sequence>
<xsd:element name="color" type="ColorType"/>
<xsd:element name="position" type="PointType"/>
<xsd:element name="bounds" type="BoundsType"/>
<xsd:element name="font" type="FontType"/>
<xsd:element name="string" type="xsd:string"/>
</xsd:sequence>
<xsd:attribute name="angle" type="xsd:double" use="required"/>
<xsd:attribute name="maxascent" type="xsd:integer" use="required"/>
</xsd:complexType>
The text string itself is a simple
<string/>
element, but the font is a complex element that requires a
type definition:
<!--Type for a font used by a sketch text element -->
<xsd:complexType name="FontType">
<xsd:attribute name="fontname" type="xsd:string" use="required"/>
<xsd:attribute name="fontstyle" use="required">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="plain"/>
<xsd:enumeration value="bold"/>
<xsd:enumeration value="italic"/>
<xsd:enumeration value="bold-italic"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
The style attribute for the
<font/>
element can be only one of four fixed values. You impose this con-
straint by defining an enumeration of the four possible string values within a
simpleType
definition for the
attribute value. The
xsd:simpleType
definition is implicitly associated with the
style
attribute value be-
cause the type definition is a child of the
xsd:attribute
element.
The Complete Sketcher Schema
If you assemble all the fragments into a single file, you have the following definition for the Sketcher schema
that defines XML documents containing a sketch:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">