Adding HTML-Style Text: XHTML
Adding HTML-Style Text: XHTML
Since XML lets you define any tags you want, it makes sense to define a set of tags
that look like HTML.
The XHTML standard does exactly that, in fact. You'll see more about that towards
the end of the SAX
tutorial. For now, type the text highlighted below to define a slide with a couple of
list item entries that
use an HTML-style <em>tag for emphasis (usually rendered as italicized text):
...
<!TITLESLIDE>
<slidetype="all">
<title>WakeuptoWonderWidgets!</title>
</slide>
<!-- OVERVIEW -->
<slide type="all">
<title>Overview</title>
<item>Why <em>WonderWidgets</em> are great</item>
<item>Who <em>buys</em> WonderWidgets</item>
</slide>
</slideshow>
We'll see later that defining a title element conflicts with the XHTML element that
uses the same name.
We'll discuss the mechanism that produces the conflict (the DTD) and several
possible solutions when
we cover Parsing the Parameterized DTD.
<item>Who<em>buys</em>WonderWidgets</item>
</slide>
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/1_write.html (4 of 6) [8/22/2001 12:52:01 PM]
1. Writing a Simple XML File
</slideshow>
Note that any element can be empty element. All it takes is ending the tag with
"/>" instead of ">". You
could do the same thing by entering <item></item>, which is equivalent.
Note:
Another factor that makes an XML file well-formed is proper nesting. So
<b><i>sometext</i></b>is well-formed, because the <i>...</i>
sequence is
completely nested within the <b>..</b>tag. This sequence, on the other hand,
is not
well-formed: <b><i>sometext</b></i>.
Predefined Entities
An entity reference like &contains a name (in this case, amp) between the
start and end
delimiters. The text it refers to (&) is substituted for the name, like a macro in a C
or C++ program. The
following table shows the predefined entities for special characters.
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/4_refs.html (1 of 5) [8/22/2001 12:52:02 PM]
4. Substituting and Inserting Text
Character Reference
& &
< <
> >
" "
' '
Character References
A character reference like “contains a hash mark (#) followed by a
number. The number is the
Unicode value for a single character, such as 65 for the letter A, 147 for the leftcurly quote, or 148 for
the right-curly quote. In this case, the "name" of the entity is the hash mark
followed by the digits that
identify the character.
<title>Overview</title>
...
</slide>
<slide type="exec">
<title>Financial Forecast</title>
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/4_refs.html (2 of 5) [8/22/2001 12:52:02 PM]
4. Substituting and Inserting Text