Java Reference
In-Depth Information
<xsd:element name="sketch" type="SketchType"/>
This declares the contents of an XML document for a sketch to be a <sketch/> element that has zero or
more elements of any of the types that appeared in the preceding xsd:choice element. This is exactly what
is required to accommodate any sketch, so this single declaration defines the entire contents of all possible
sketches. All you need is to fill in a few details for the element types. I think you know enough about XML
Schema to put together a schema for Sketcher documents.
A SCHEMA FOR SKETCHER
As I noted when I discussed a DTD for Sketcher, an XML document that defines a sketch can have a very
simple structure. Essentially, it can consist of a <sketch/> element that contains a sequence of zero or more
elements that define lines, rectangles, circles, curves, or text. These child elements may be in any sequence,
and there can be any number of them. To accommodate the fact that any given child element must be one of
five types of elements, you could use some of the XML fragments from earlier sections to make an initial
stab at an outline of a Sketcher schema like this:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--The entire document content -->
<xsd:element name="sketch" type="SketchType"/>
<!--Type for a sketch root element -->
<xsd:complexType name="SketchType">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="line" type="LineType"/>
<xsd:element name="rectangle" type="RectangleType"/>
<xsd:element name="circle" type="CircleType"/>
<xsd:element name="curve" type="CurveType"/>
<xsd:element name="text" type="TextType"/>
</xsd:choice>
</xsd:complexType>
<!--Other definitions that are needed... -->
</xsd:schema>
This document references the XML Schema language namespace, so it's evidently a definition of a
schema. The documents that this schema defines have no namespace specified, so elements on documents
conforming to this schema do not need to be qualified. The entire content of a Sketcher document is declared
to be an element with the name sketch that is of type SketchType . The <sketch/> element is the root ele-
ment, and because it can have child elements, it must be defined as a complex type. The child elements with-
in a <sketch/> element are the elements specified by the xsd:choice element, which represents a selection
of one of the five complex elements that can occur in a sketch. The minOccurs and maxOccurs attribute val-
ues for the xsd:choice element determines that there may be any number of such elements, including zero.
Thus, this definition accommodates XML documents describing any Sketcher sketch. All you now need to
do is fill in the definitions for the possible varieties of child elements.
Search WWH ::




Custom Search