Java Reference
In-Depth Information
The XML Element for a Sketch
A sketch is a very simple document. It's basically a sequence of lines, circles, rectangles, curves, and text.
You can therefore define the root element <sketch> in the DTD as the following:
<!ELEMENT sketch (line|circle|rectangle|curve|text)*>
This says that a sketch consists of zero or more of any of the elements between the parentheses. You now
need to define each of these elements.
The XML Element for a Line Element in a Sketch
A line is easy. It is defined by its location, which is its start point and a Line2D.Double object. It also has
an orientation — its rotation angle — and a color. You could define a <line> element like this:
<!ELEMENT line (color, position, bounds, endpoint)>
<!ATTLIST line
angle CDATA #REQUIRED
>
A line is fully defined by two points, its position, and its end point, which is relative to the origin. A line
has a bounds rectangle, as all the elements do, so you define another type of element, <bounds> , for this
rectangle.
You could define color by a color attribute to the <line> element with a set of alternative values, but to
allow the flexibility for lines of any color, it would be better to define a <color> element with three attrib-
utes for RGB values. In this case you can define the <color> element as
<!ELEMENT color EMPTY>
<!ATTLIST color
R CDATA #REQUIRED
G CDATA #REQUIRED
B CDATA #REQUIRED
>
You can now define the <position> and <endpoint> elements. These are both points defined by an ( x ,
y ) coordinate pair, so you would sensibly define them consistently. Empty elements with attributes are the
most economical way here, and you can use a parameter entity for the attributes:
<!ENTITY % coordinates "x CDATA #REQUIRED y CDATA #REQUIRED">
<!ELEMENT position EMPTY>
<!ATTLIST position %coordinates;>
<!ELEMENT endpoint EMPTY>
<!ATTLIST endpoint %coordinates;>
You can define a <bounds> element with the coordinates of its top-left corner and the width and height
as attributes:
<!ENTITY % dimensions "width CDATA #REQUIRED height CDATA #REQUIRED">
<!ELEMENT bounds EMPTY>
<!ATTLIST bounds
%coordinates;
Search WWH ::




Custom Search