Java Reference
In-Depth Information
A parameter entity declaration must precede its use in a DTD.
The substitution string in a parameter entity declaration is parsed and can include parameter and general
entity references. As with general entities, you can also define a parameter entity by a reference to a URI
containing the substitution string.
Other Types of Attribute Values
There are a further eight possibilities for specifying the type of the attribute value. I'm not going into detail
on these, but a brief description of each is in Table 22-3 so you can recognize them:
TABLE 22-3 : Other Types of Attribute Values
VALUE DESCRIPTION
ENTITY An entity defined in the DTD. An entity here is a name identifying an unparsed entity defined elsewhere in
the DTD by an ENTITY tag. The entity may or may not contain text. An entity could represent something
very simple, such as < , which refers to a single character, or it could represent something more substan-
tial, such as an image.
ENTITIES A list of entities defined in the DTD, separated by spaces.
ID An ID is a unique name identifying an element in a document. This is to enable internal references to a par-
ticular element from elsewhere in the document.
IDREF A reference to an element elsewhere in a document via its ID.
IDREFS A list of references to IDs, separated by spaces.
NMTOKEN A name conforming to the XML definition of a name. This just says that the value of the attribute is consist-
ent with the XML rules for a name.
NMTOKENS A list of name tokens, separated by spaces.
NOTATION A name identifying a notation — which is typically a format specification for an entity such as a JPEG or
PostScript file. The notation is identified elsewhere in the DTD using a NOTATION tag that may also identify
an application capable of processing an entity in the given format.
A DTD for Sketcher
With what you know of XML and DTDs, you can have a stab at putting together a DTD for storing Sketcher
files as XML. As I said before, an XML language has already been defined for representing and communic-
ating two-dimensional graphics. This is called Scalable Vector Graphics, and you can find it at www.w3.org/
TR/SVG/ . Although this would be the choice for transferring 2D graphics as XML documents in a real-
world context, the objective here is to exercise your knowledge of XML and DTDs, so you'll reinvent your
own version of this wheel, even though it has fewer spokes and may wobble a bit.
First, let's consider what the general approach is going to be. The objective is to define a DTD that en-
ables you to exercise the Java API for XML with Sketcher, so you define the language to make it an easy
fit to Sketcher rather than worrying about the niceties of the best way to represent each geometric element.
Because Sketcher was a vehicle for trying out various capabilities of the Java class libraries, it evolved in a
somewhat Topsy-like fashion, with the result that the classes defining geometric entities are not necessarily
ideal. However, you just map these directly in XML to avoid the mathematical hocus pocus that would be
necessary if you adopted a more formal representation of geometry in XML.
You want to be able to reconstruct the elements in an existing sketch from the XML, so this does not ne-
cessarily require the same data as you used to create the elements in the first place. Essentially, you want to
reconstruct the fields in an Element object. For the geometric elements, this means reconstructing the object
that represents a particular element, plus its position, rotation angle, bounding rectangle, and color.
 
 
Search WWH ::




Custom Search