Java Reference
In-Depth Information
<!--Type for a sketch circle element -->
<xsd:complexType name="CircleType">
<xsd:sequence>
<xsd:element name="color" type="ColorType"/>
<xsd:element name="position" type="PointType"/>
<xsd:element name="bounds" type="BoundsType"/>
</xsd:sequence>
<xsd:attribute name="diameter" use="required">
<xsd:simpleType>
<xsd:restriction base="xsd:double">
<xsd:minExclusive value="2.0"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="angle" type="xsd:double" use="required"/>
</xsd:complexType>
The child elements appear within a sequence element, so their sequence is fixed. You have the diameter
and angle for a circle specified by attributes that both have values of type double , and are both mandatory.
The diameter is restricted to non-negative values with a minimum of 2.0.
Defining a Curve Element Type
A type for the curve element introduces something new because the number of child elements is variable.
A curve is defined by the origin plus one or more points, so the type definition must allow for an unlimited
number of child elements defining points. Here's how you can accommodate that:
<!--Type for a sketch curve element -->
<xsd:complexType name="CurveType">
<xsd:sequence>
<xsd:element name="color" type="ColorType"/>
<xsd:element name="position" type="PointType"/>
<xsd:element name="bounds" type="BoundsType"/>
<xsd:element name="point" type="PathPointType" minOccurs="1"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="angle" type="xsd:double" use="required"/>
</xsd:complexType>
The flexibility in the number of point elements is specified through the minOccurs and maxOccurs at-
tribute values. The value of 1 for minOccurs ensures that there is always at least one, and the unbounded
value for maxOccurs allows an unlimited number of point elements to be present. These elements are going
to be points with floating-point coordinates because that's what you get from the GeneralPath object that
defines a curve. You can define this element type like this:
<!--Type for elements representing points in a general path -->
<xsd:complexType name="PathPointType">
<xsd:attribute name="x" type="xsd:double" use="required"/>
<xsd:attribute name="y" type="xsd:double" use="required"/>
</xsd:complexType>
Search WWH ::




Custom Search