, Java XML Tutorial 1_1 

[ Pobierz całość w formacie PDF ]

CDATA "Unparsed character data". (For normal people, a text string.)
ID A name that no other ID attribute shares.
IDREF A reference to an ID defined elsewhere in the document.
IDREFS A space-separated list containing one or more ID references.
The name of an entity defined in the DTD.
ENTITY
ENTITIES A space-separated list of entities.
A valid XML name composed of letters, numbers, hyphens,
NMTOKEN
underscores, and colons.
NMTOKENS A space-separated list of names.
The name of a DTD-specified notation, which describes a non-
NOTATION
XML data format, such as those used for image files.*
*This is a rapidly obsolescing specification which will be discussed in greater length
towards the end of this section.
When the attribute type consists of a parenthesized list of choices separated by vertical bars, the attribute
must use one of the specified values. For an example, add the text highlighted below to the DTD:
type (tech | exec | all) #IMPLIED
>
This specification says that the slide element's type attribute must be given as type="tech",
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/5c_dtd.html (2 of 7) [8/22/2001 12:52:00 PM]
5c. Attributes and Entities in a DTD
type="exec", or type="all". No other values are acceptable. (DTD-aware XML editors can use
such specifications to present a pop-up list of choices.)
The last entry in the attribute specification determines the attributes default value, if any, and tells
whether or not the attribute is required. The table below shows the possible choices.
Specification Specifies...
#REQUIRED The attribute value must be specified in the document.
The value need not be specified in the document. If it
#IMPLIED
isn't, the application will have a default value it uses.
The default value to use, if a value is not specified in
"defaultValue"
the document.
The value to use. If the document specifies any value at
#FIXED "fixedValue"
all, it must be the same.
Defining Entities in the DTD
So far, you've seen predefined entities like & and you've seen that an attribute can reference an
entity. It's time now for you to learn how to define entities of your own.
Note: The XML defined here is contained in slideSample06.xml. (The browsable
version is slideSample06-xml.html.) The output is shown in Echo09-06.
Add the text highlighted below to the DOCTYPE tag in your XML file:
]>
The ENTITY tag name says that you are defining an entity. Next comes the name of the entity and its
definition. In this case, you are defining an entity named "product" that will take the place of the product
name. Later when the product name changes (as it most certainly will), you will only have to change the
name one place, and all your slides will reflect the new value.
The last part is the substitution string that replaces the entity name whenever it is referenced in the XML
document. The substitution string is defined in quotes, which are not included when the text is inserted
into the document.
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/5c_dtd.html (3 of 7) [8/22/2001 12:52:00 PM]
5c. Attributes and Entities in a DTD
Just for good measure, we defined two versions, one singular and one plural, so that when the marketing
mavens come up with "Wally" for a product name, you will be prepared to enter the plural as "Wallies"
and have it substituted correctly.
Note: Truth be told, this is the kind of thing that really belongs in an external DTD. That
way, all your documents can reference the new name when it changes. But, hey, this is an
example...
Now that you have the entities defined, the next step is to reference them in the slide show. Make the
changes highlighted below to do that:
title="WonderWidget&product; Slide Show"
...
Wake up to WonderWidgets&products;!
Overview
Why WonderWidgets&products; are great
Who buys WonderWidgets&products;
The points to notice here are that entities you define are referenced with the same syntax
(&entityName;) that you use for predefined entities, and that the entity can be referenced in an
attribute value as well as in an element's contents.
Echoing the Entity References
When you run the Echo program on this version of the file, here is the kind of thing you see:
ELEMENT:
CHARS: Wake up to
CHARS: WonderWidgets
CHARS: !
END_ELM:
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/5c_dtd.html (4 of 7) [8/22/2001 12:52:00 PM]
5c. Attributes and Entities in a DTD
Note that the existence of the entity reference generates an extra call to the characters method, and
that the text you see is what results from the substitution.
Additional Useful Entities
Here are three other examples for entity definitions that you might find useful when you write an XML
document:
Referencing External Entities
You can also use the SYSTEM or PUBLIC identifier to name an entity that is defined in an external file.
You'll do that now.
Note: The XML defined here is contained in slideSample07.xml and in
copyright.xml. (The browsable versions are slideSample07-xml.html and
copyright-xml.html.) The Echo output is shown in Echo09-07.
To reference an external entity, add the text highlighted below to the DOCTYPE statement in your XML
file:
]>
This definition references a copyright message contained in a file named copyright.xml. Create that
file and put some interesting text in it, perhaps something like this:
This is the standard copyright message that our lawyers
make us put everywhere so we don't have to shell out a
million bucks every time someone spills hot coffee in their
lap...
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/5c_dtd.html (5 of 7) [8/22/2001 12:52:00 PM] [ Pobierz całość w formacie PDF ]
  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • osy.pev.pl