Java Reference
In-Depth Information
Defining Line Elements
Let's define the same XML elements in the schema for Sketcher as the DTD for Sketcher defines. On that
basis, a line element has four child elements specifying the color, position, and end point for a line, plus an
attribute that specifies the rotation angle. You could define the type for a <line/> element in the schema
like this:
<!--Type for a sketch line element -->
<xsd:complexType name="LineType">
<xsd:sequence>
<xsd:element name="color" type="ColorType"/>
<xsd:element name="position" type="PointType"/>
<xsd:element name="bounds" type="BoundsType"/>
<xsd:element name="endpoint" type="PointType"/>
</xsd:sequence>
<xsd:attribute name="angle" type="xsd:double" use="required"/>
</xsd:complexType>
This defines the type for a <line/> element in a sketch. An element of type LineType contains four
child elements, <color/> , <position/> , <bounds/> , and <endpoint/> . These are enclosed within a
<sequence/> schema definition element, so they must all be present and must appear in a sketch document
in the sequence in which they are specified here. The element type definition also specifies an attribute with
the name angle that must be included in any element of type LineType .
Of course, you now must define the types that you have used in the definition of the complex type,
LineType : the ColorType , PointType , and BoundsType element types.
Defining a Type for Color Elements
As I discussed in the context of the DTD for Sketcher, the data for a <color/> element is supplied by three
attributes that specify the RGB values for the color. You can therefore define the element type like this:
<!--Type for a sketch element color -->
<xsd:complexType name="ColorType">
<xsd:attribute name="R" type="xsd:nonNegativeInteger" use="required"/>
<xsd:attribute name="G" type="xsd:nonNegativeInteger" use="required"/>
<xsd:attribute name="B" type="xsd:nonNegativeInteger" use="required"/>
</xsd:complexType>
This is a relatively simple complex type definition. There are just the three attributes — R, G, and B —
that all have integer values that can be 0 or greater, and are all mandatory.
You could improve this. As well as being non-negative integers, the color component values must be
between 0 and 255. You could express this by adding facets for the color attributes, as follows:
<!--Type for a sketch element color -->
<xsd:complexType name="ColorType">
<xsd:attribute name="R" use="required">
<xsd:simpleType>
<xsd:restriction base="xsd:nonNegativeInteger">
<xsd:maxInclusive value="255"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
Search WWH ::




Custom Search