[ Pobierz całość w formacie PDF ]

earmarked for a mostly technical or mostly executive audience with type="tech" or type="exec",
or identified as suitable for both with type="all".
More importantly, though, this example illustrates the difference between things that are more usefully
defined as elements (the title element) and things that are more suitable as attributes (the type attribute).
The visibility heuristic is primarily at work here. The title is something the audience will see. So it is an
element. The type, on the other hand, is something that never gets presented, so it is an attribute. Another
way to think about that distinction is that an element is a container, like a bottle. The type is a
characteristic of the container (is it tall or short, wide or narrow). The title is a characteristic of the
contents (water, milk, or tea). These are not hard and fast rules, of course, but they can help when you
design your own XML structures.
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/1_write.html (3 of 6) [8/22/2001 12:52:01 PM]
1. Writing a Simple XML File
Adding HTML-Style Text
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 tag for emphasis (usually rendered as italicized text):
...
Wake up to WonderWidgets!
Overview
Why WonderWidgets are great
Who buys WonderWidgets
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.
Adding an Empty Element
One major difference between HTML and XML, though, is that all XML must be well-formed -- which
means that every tag must have an ending tag or be an empty tag. You're getting pretty comfortable with
ending tags, by now. Add the text highlighted below to define an empty list item element with no
contents:
...
Overview
Why WonderWidgets are great
Who buys WonderWidgets
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
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 , which is equivalent.
Note:
Another factor that makes an XML file well-formed is proper nesting. So
some text is well-formed, because the ... sequence is
completely nested within the .. tag. This sequence, on the other hand, is not
well-formed: some text.
The Finished Product
Here is the completed version of the XML file:
title="Sample Slide Show"
date="Date of publication"
author="Yours Truly"
>
Wake up to WonderWidgets!
Overview
Why WonderWidgets are great
Who buys WonderWidgets
Now that you've created a file to work with, you're ready to write a program to echo it using the SAX
parser. You'll do that in the next section.
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/1_write.html (5 of 6) [8/22/2001 12:52:01 PM]
1. Writing a Simple XML File
Top Contents Index Glossary
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/sax/1_write.html (6 of 6) [8/22/2001 12:52:01 PM]
4. Substituting and Inserting Text
Top Contents Index Glossary
4. Substituting and Inserting Text
The next thing we want to with the parser is to customize it a
Link Summary
bit, so you can see how to get information it usually ignores.
Exercise Links
But before we can do that, you're going to need to learn a few
more important XML concepts. In this section, you'll learn
slideSample03.xml
about:
slideSample03-xml.html
Echo07-03
Handling Special Characters ("
slideSample04.xml
Handling Text with XML-style syntax slideSample04-xml.html
Echo07-04
Handling Special Characters
API Links
In XML, an entity is an XML structure (or plain text) that has
LexicalHandler
a name. Referencing the entity by name causes it to be
inserted into the document in place of the entity reference. To
Glossary Terms
create an entity reference, the entity name is surrounded by an
ampersand and a semicolon, like this:
CDATA, DTD, entity, entity
&entityName;
reference
Later, when you learn how to write a DTD, you'll see that you
can define your own entities, so that &yourEntityName; expands to all the text you defined for that
entity. For now, though, we'll focus on the predefined entities and character references that don't require
any special definitions.
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 left-curly 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.
Using an Entity Reference in an XML Document
Suppose you wanted to insert a line like this in your XML document:
Market Size [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • forum-gsm.htw.pl