Cover | Table of Contents
<HEAD> and <BODY>, for example, are
tightly integrated into the HTML standard and cannot be changed
or extended. XML, on the other hand, allows you to create your
own markup tags and configure each to your liking: for example,
<HeadingA>, <Sidebar>, <Quote>, or
<ReallyWildFont>. Each of these elements can be
defined through your own document type definitions and
stylesheets and applied to one or more XML documents. Thus,
it is important to realize that there are no “correct” tags for an XML
document, except those you define yourself.<Body> This is text formatted according to the Body element </Body>This element consists of two tags, an opening tag which places the name of the element between a less-than sign (
<) and a greater-than
sign (>), and a closing tag which is identical except for the
forward slash (/) that appears before the element name. Like HTML,
the text contained
between the opening and closing tags is considered part of the
element and is formatted according to the element’s rules.<Price currency="Euro">25.43</Price>Here, the attribute is specified inside of the opening tag and is called “currency.” It is given a value of “Euro,” which is expressed inside quotation marks. Attributes are often used to further refine or modify the default behavior of an element.
<Picture src="blueball.gif"></Picture> <Picture src="blueball.gif"/>Empty elements are often used to add nontextual content to a document, or to provide additional information to the application that is parsing the XML. Note that while the closing slash may not be used in single-tag HTML elements, it is mandatory for single-tag XML empty elements.
standalone attribute set to
“no”. For example:
<?xml version="1.0" standalone="no"?>
< or
& must use entity references instead. In addition, the
sequence ]]> must be expressed as ]]> when used as
regular text. (Entity references are discussed in further detail
later.)yes|no ] ?><?xml<!ELEMENT>
declaration, which uses the this format:
<!ELEMENT elementname rule>This declares an XML element and an associated rule, which relates the element logically in the XML document. The element name should not include
<> characters. An element name must
start with a letter or an underscore. After that, it can have any number of
letters, numbers, hyphens, periods, or underscores in its name. Element
names may not start with the string xml, in any variation of
upper- or lowercase. You can use a colon in element names only if you are
using namespaces; otherwise, it is forbidden.<!ELEMENT library ANY>Using the
ANY keyword allows you to include both other tags
and general character data within the element. However, you may want to
specify a situation where you want only general characters appearing.
This type of data is better known as parsed character data, or
PCDATA for short. You can specify that an element can
contain only PCDATA with the following declaration:
<!ELEMENT title (#PCDATA)>Remember, this declaration means that any character data that is not an element can appear between the element tags. Therefore, it’s legal to write the following in your XML document:
<title></title> <title>XML Pocket Reference</title> <title>Java Network Programming</title>
http://www.w3.org/Style/XSL/. This section will still provide
you with a firm understanding of how XSL is meant to be used.<?xml version="1.0"?>
<OReilly:Book title="XML Comments">
<OReilly:Chapter title="Working with XML">
<OReilly:Image src="http://www.oreilly.com/1.gif"/>
<OReilly:HeadA>Starting XML</OReilly:HeadA>
<OReilly:Body>If you haven\(ast used XML, then ...
</OReilly:Body>
</OReilly:Chapter>
</OReilly:Book>
to the following HTML:
<HTML>
<HEAD>
<TITLE>XML Comments</TITLE>
</HEAD>
<BODY>
<H1>Working with XML</H1>
<img src="http://www.oreilly.com/1.gif"/>
<H2>Starting XML</H2>
<P>If you haven\(ast used XML, then ...</P>
</BODY>
</HTML>
If you look carefully, you can see a predefined hierarchy that remains
from the source content to the resulting content. To venture a guess,
the <OReilly:Book> element probably maps to the <HTML>,
<HEAD>, <TITLE>, and <BODY> elements in HTML.
The <OReilly:Chapter> element maps to the HTML <H1>
element, the <OReilly:Image> element maps to the <img>
element, and so on.<paragraph id="attack">Suddenly the skies were filled with aircraft.</paragraph>You can think of IDs in XML documents as street addresses: they provide a unique identifier for an element within a document. However, just as there might be an identical address in a different city, an element in a different document might have the same ID. Consequently, you can tie together an ID with the document’s URI, as shown below:
http://www.oreilly.com/documents/story.xml#attackThe combination of a document’s URI and an element’s ID should uniquely identify that element throughout the universe. Remember that an ID attribute does not need to be named ”id,“ as we showed in the first example. You can name it anything you want, as long as you define it as an XML ID in the document’s DTD. (However, using ”id“ is preferred in the event that the XML processor does not read the DTD.)
Return to XML Pocket Reference