Index: head/en_US.ISO8859-1/books/fdp-primer/structure/chapter.xml
===================================================================
--- head/en_US.ISO8859-1/books/fdp-primer/structure/chapter.xml (revision 46364)
+++ head/en_US.ISO8859-1/books/fdp-primer/structure/chapter.xml (revision 46365)
@@ -1,305 +1,305 @@
Documentation Directory StructureFiles and directories in the
doc/ tree follow a
structure meant to:Make it easy to automate converting the document to other
formats.Promote consistency between the different documentation
organizations, to make it easier to switch between working on
different documents.Make it easy to decide where in the tree new documentation
should be placed.In addition, the documentation tree must accommodate
documents in many different languages and encodings. It is
important that the documentation tree structure does not enforce
any particular defaults or cultural preferences.The Top Level,
doc/There are two types of directory under
doc/, each with very
specific directory names and meanings.DirectoryUsageshareContains files that are not specific to the various
translations and encodings of the documentation.
Contains subdirectories to further categorize the
information. For example, the files that comprise the
&man.make.1; infrastructure are in
share/mk, while
the additional XML support files
(such as the &os; extended DocBook
DTD) are in share/xml.lang.encodingOne directory exists for each available translation
and encoding of the documentation, for example
en_US.ISO8859-1/
and zh_TW.UTF-8/.
The names are long, but by fully specifying the language
and encoding we prevent any future headaches when a
translation team wants to provide documentation in the
same language but in more than one encoding. This also
avoids problems that might be caused by a future switch
to Unicode.The
lang.encoding/
DirectoriesThese directories contain the documents themselves. The
documentation is split into up to three more categories at
this level, indicated by the different directory names.DirectoryUsagearticlesDocumentation marked up as a DocBook
article (or equivalent). Reasonably
short, and broken up into sections. Normally only
available as one XHTML file.booksDocumentation marked up as a DocBook
book (or equivalent). Book length,
and broken up into chapters. Normally available as both
one large XHTML file (for people with
fast connections, or who want to print it easily from a
browser) and as a collection of linked, smaller
files.manFor translations of the system manual pages. This
directory will contain one or more mann
directories, corresponding to the sections that have
been translated.Not every lang.encoding
directory will have all of these subdirectories. It depends
on how much translation has been accomplished by that
translation team.Document-Specific InformationThis section contains specific notes about particular
documents managed by the FDP.The Handbookbooks/handbook/The Handbook is written in DocBook XML
using the &os; DocBook extended DTD.The Handbook is organized as a DocBook
book. The book is divided into
parts, each of which contains several
chapters. chapters are
further subdivided into sections (sect1)
and subsections (sect2,
sect3) and so on.Physical OrganizationThere are a number of files and directories within the
handbook directory.The Handbook's organization may change over time, and
this document may lag in detailing the organizational
- changes. Post questions about Handbook organization to
+ changes. Post questions about Handbook organization to the
&a.doc;.MakefileThe Makefile defines some
variables that affect how the XML
source is converted to other formats, and lists the
various source files that make up the Handbook. It then
includes the standard doc.project.mk,
to bring in the rest of the code that handles converting
documents from one format to another.book.xmlThis is the top level document in the Handbook. It
contains the Handbook's DOCTYPE
declaration, as well as the elements that
describe the Handbook's structure.book.xml uses parameter
entities to load in the files with the
.ent extension. These files
(described later) then define general
entities that are used throughout the rest of the
Handbook.directory/chapter.xmlEach chapter in the Handbook is stored in a file
called chapter.xml in a separate
directory from the other chapters. Each directory is
named after the value of the id
attribute on the chapter
element.For example, if one of the chapter files
contains:chapter id="kernelconfig"
...
chapterThen it will be called
chapter.xml in the
kernelconfig directory. In general,
the entire contents of the chapter are in this one
file.When the XHTML version of the
Handbook is produced, this will yield
kernelconfig.html. This is because
of the id value, and is not related to
the name of the directory.In earlier versions of the Handbook, the files were
stored in the same directory as
book.xml, and named after the value
of the id attribute on the file's
chapter element. Now, it is possible
to include images in each chapter. Images for each
Handbook chapter are stored within share/images/books/handbook.
The localized version of these images should be
placed in the same directory as the XML
sources for each chapter. Namespace collisions are
inevitable, and it is easier to work with several
directories with a few files in them than it is to work
with one directory that has many files in it.A brief look will show that there are many directories
with individual chapter.xml files,
including basics/chapter.xml,
introduction/chapter.xml, and
printing/chapter.xml.Do not name chapters or directories after
their ordering within the Handbook. This ordering can
change as the content within the Handbook is
reorganized. Reorganization should be possible without
renaming files, unless entire chapters are being
promoted or demoted within the hierarchy.The chapter.xml files are not
complete XML documents that can be
built individually. They can only be built
as parts of the whole Handbook.
Index: head/en_US.ISO8859-1/books/fdp-primer/xml-primer/chapter.xml
===================================================================
--- head/en_US.ISO8859-1/books/fdp-primer/xml-primer/chapter.xml (revision 46364)
+++ head/en_US.ISO8859-1/books/fdp-primer/xml-primer/chapter.xml (revision 46365)
@@ -1,1433 +1,1433 @@
XML PrimerMost FDP documentation is written with
markup languages based on XML. This chapter
explains what that means, how to read and understand the
documentation source, and the XML techniques
used.Portions of this section were inspired by Mark Galassi's
Get
Going With DocBook.OverviewIn the original days of computers, electronic text was
simple. There were a few character sets like
ASCII or EBCDIC, but that
was about it. Text was text, and what you saw really was what
you got. No frills, no formatting, no intelligence.Inevitably, this was not enough. When text is in a
machine-usable format, machines are expected to be able to use
and manipulate it intelligently. Authors want to indicate that
certain phrases should be emphasized, or added to a glossary, or
made into hyperlinks. Filenames could be shown in a
typewriter style font for viewing on screen, but
as italics when printed, or any of a myriad of
other options for presentation.It was once hoped that Artificial Intelligence (AI) would
make this easy. The computer would read the document and
automatically identify key phrases, filenames, text that the
reader should type in, examples, and more. Unfortunately, real
life has not happened quite like that, and computers still
require assistance before they can meaningfully process
text.More precisely, they need help identifying what is what.
Consider this text:
To remove /tmp/foo, use
&man.rm.1;.&prompt.user; rm /tmp/foo
It is easy to see which parts are filenames, which are
commands to be typed in, which parts are references to manual
pages, and so on. But the computer processing the document
cannot. For this we need markup.Markup is commonly used to describe
adding value or increasing cost.
The term takes on both these meanings when applied to text.
Markup is additional text included in the document,
distinguished from the document's content in some way, so that
programs that process the document can read the markup and use
it when making decisions about the document. Editors can hide
the markup from the user, so the user is not distracted by
it.The extra information stored in the markup
adds value to the document. Adding the
markup to the document must typically be done by a
person—after all, if computers could recognize the text
sufficiently well to add the markup then there would be no need
to add it in the first place. This
increases the cost (the effort required) to
create the document.The previous example is actually represented in this
document like this:paraTo remove filename/tmp/foofilename, use &man.rm.1;.parascreen&prompt.user; userinputrm /tmp/foouserinputscreenThe markup is clearly separate from the content.Markup languages define what the markup means and how it
should be interpreted.Of course, one markup language might not be enough. A
markup language for technical documentation has very different
requirements than a markup language that is intended for cookery
recipes. This, in turn, would be very different from a markup
language used to describe poetry. What is really needed is a
first language used to write these other markup languages. A
meta markup language.This is exactly what the eXtensible Markup
Language (XML) is. Many markup languages
have been written in XML, including the two
most used by the FDP,
XHTML and DocBook.Each language definition is more properly called a grammar,
vocabulary, schema or Document Type Definition
(DTD). There are various languages to
specify an XML grammar, or
schema.A schema is a
complete specification of all the elements
that are allowed to appear, the order in which they should
appear, which elements are mandatory, which are optional, and so
forth. This makes it possible to write an
XML parser which reads
in both the schema and a document which claims to conform to the
schema. The parser can then confirm whether or not all the
elements required by the vocabulary are in the document in the
right order, and whether there are any errors in the markup.
This is normally referred to as
validating the document.Validation confirms that the choice of
elements, their ordering, and so on, conforms to that listed
in the grammar. It does not check
whether appropriate markup has been used
for the content. If all the filenames in a document were
marked up as function names, the parser would not flag this as
an error (assuming, of course, that the schema defines
elements for filenames and functions, and that they are
allowed to appear in the same place).Most contributions to the Documentation
Project will be content marked up in either
XHTML or DocBook, rather than alterations to
the schemas. For this reason, this book will not touch on how
to write a vocabulary.Elements, Tags, and AttributesAll the vocabularies written in XML share
certain characteristics. This is hardly surprising, as the
philosophy behind XML will inevitably show
through. One of the most obvious manifestations of this
philosophy is that of content and
elements.Documentation, whether it is a single web page, or a lengthy
book, is considered to consist of content. This content is then
divided and further subdivided into elements. The purpose of
adding markup is to name and identify the boundaries of these
elements for further processing.For example, consider a typical book. At the very top
level, the book is itself an element. This book
element obviously contains chapters, which can be considered to
be elements in their own right. Each chapter will contain more
elements, such as paragraphs, quotations, and footnotes. Each
paragraph might contain further elements, identifying content
that was direct speech, or the name of a character in the
story.It may be helpful to think of this as
chunking content. At the very top level is one
chunk, the book. Look a little deeper, and there are more
chunks, the individual chapters. These are chunked further into
paragraphs, footnotes, character names, and so on.Notice how this differentiation between different elements
of the content can be made without resorting to any
XML terms. It really is surprisingly
straightforward. This could be done with a highlighter pen and
a printout of the book, using different colors to indicate
different chunks of content.Of course, we do not have an electronic highlighter pen, so
we need some other way of indicating which element each piece of
content belongs to. In languages written in
XML (XHTML, DocBook, et
al) this is done by means of tags.A tag is used to identify where a particular element starts,
and where the element ends. The tag is not part of
the element itself. Because each grammar was
normally written to mark up specific types of information, each
one will recognize different elements, and will therefore have
different names for the tags.For an element called
element-name the start tag will
normally look like element-name.
The corresponding closing tag for this element is element-name.Using an Element (Start and End Tags)XHTML has an element for indicating
that the content enclosed by the element is a paragraph,
called p.pThis is a paragraph. It starts with the start tag for
the 'p' element, and it will end with the end tag for the 'p'
element.ppThis is another paragraph. But this one is much shorter.pSome elements have no content. For example, in
XHTML, a horizontal line can be included in
the document. For these empty elements,
XML introduced a shorthand form that is
completely equivalent to the two-tag version:Using an Element Without ContentXHTML has an element for indicating a
horizontal rule, called hr. This element
does not wrap content, so it looks like this:pOne paragraph.phrhrpThis is another paragraph. A horizontal rule separates this
from the previous paragraph.pThe shorthand version consists of a single tag:pOne paragraph.phrpThis is another paragraph. A horizontal rule separates this
from the previous paragraph.pAs shown above, elements can contain other elements. In the
book example earlier, the book element contained all the chapter
elements, which in turn contained all the paragraph elements,
and so on.Elements Within Elements; empThis is a simple emparagraphem where some
of the emwordsem have been ememphasizedem.pThe grammar consists of rules that describe which elements
can contain other elements, and exactly what they can
contain.People often confuse the terms tags and elements, and use
the terms as if they were interchangeable. They are
not.An element is a conceptual part of your document. An
element has a defined start and end. The tags mark where the
element starts and ends.When this document (or anyone else knowledgeable about
XML) refers to
the p tag
they mean the literal text consisting of the three characters
<, p, and
>. But the phrase
the p element refers to the
whole element.This distinction is very subtle. But
keep it in mind.Elements can have attributes. An attribute has a name and a
value, and is used for adding extra information to the element.
This might be information that indicates how the content should
be rendered, or might be something that uniquely identifies that
occurrence of the element, or it might be something else.An element's attributes are written
inside the start tag for that element, and
take the form
attribute-name="attribute-value".In XHTML, the p
element has an attribute called
align, which suggests an
alignment (justification) for the paragraph to the program
displaying the XHTML.The align attribute can
take one of four defined values, left,
center, right and
justify. If the attribute is not specified
then the default is left.Using an Element with an Attributep align="left"The inclusion of the align attribute
on this paragraph was superfluous, since the default is left.pp align="center"This may appear in the center.pSome attributes only take specific values, such as
left or justify. Others
allow any value.Single Quotes Around Attributesp align='right'I am on the right!pAttribute values in XML must be enclosed
in either single or double quotes. Double quotes are
traditional. Single quotes are useful when the attribute value
contains double quotes.Information about attributes, elements, and tags is stored
in catalog files. The Documentation Project uses standard
DocBook catalogs and includes additional catalogs for
&os;-specific features. Paths to the catalog files are defined
in an environment variable so they can be found by the document
build tools.To Do…Before running the examples in this document, install
textproc/docproj from
the &os; Ports Collection. This is a
meta-port that downloads and installs
the standard programs and supporting files needed by the
Documentation Project. &man.csh.1; users must use
rehash for the shell to recognize new
- programs after after they have been installed, or log out
+ programs after they have been installed, or log out
and then log back in again.Create example.xml, and enter
this text:!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"html xmlns="http://www.w3.org/1999/xhtml"headtitleAn Example XHTML FiletitleheadbodypThis is a paragraph containing some text.ppThis paragraph contains some more text.pp align="right"This paragraph might be right-justified.pbodyhtmlTry to validate this file using an
XML parser.textproc/docproj
includes the xmllint
validating
parser.Use xmllint to validate the
document:&prompt.user; xmllint --valid --noout example.xmlxmllint returns without displaying
any output, showing that the document validated
successfully.See what happens when required elements are omitted.
Delete the line with the
title and
- /title tags, and re-run
+ title tags, and re-run
the validation.&prompt.user; xmllint --valid --noout example.xml
example.xml:5: element head: validity error : Element head content does not follow the DTD, expecting ((script | style | meta | link | object | isindex)* , ((title , (script | style | meta | link | object | isindex)* , (base , (script | style | meta | link | object | isindex)*)?) | (base , (script | style | meta | link | object | isindex)* , title , (script | style | meta | link | object | isindex)*))), got ()This shows that the validation error comes from the
fifth line of the
example.xml file and that the
content of the head is
the part which does not follow the rules of the
XHTML grammar.Then xmllint shows the line where
the error was found and marks the exact character position
with a ^ sign.Replace the title element.The DOCTYPE DeclarationThe beginning of each document can specify the name of the
DTD to which the document conforms. This
DOCTYPE declaration is used by XML parsers to
identify the DTD and ensure that the document
does conform to it.A typical declaration for a document written to conform with
version 1.0 of the XHTML
DTD looks like this:!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"That line contains a number of different components.<!The indicator shows
this is an XML declaration.DOCTYPEShows that this is an XML
declaration of the document type.htmlNames the first
element that
will appear in the document.PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"Lists the Formal Public Identifier
(FPI)
Formal Public Identifier
for the DTD to which this document
conforms. The XML parser uses this to
find the correct DTD when processing
this document.PUBLIC is not a part of the
FPI, but indicates to the
XML processor how to find the
DTD referenced in the
FPI. Other ways of telling the
XML parser how to find the
DTD are shown later."http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"A local filename or a URL to find
the DTD.>Ends the declaration and returns to the
document.Formal Public Identifiers
(FPIs)Formal Public IdentifierIt is not necessary to know this, but it is useful
background, and might help debug problems when the
XML processor can not locate the
DTD.FPIs must follow a specific
syntax:"Owner//KeywordDescription//Language"OwnerThe owner of the FPI.The beginning of the string identifies the owner of
the FPI. For example, the
FPI
"ISO 8879:1986//ENTITIES Greek
Symbols//EN" lists
ISO 8879:1986 as being the owner for
the set of entities for Greek symbols.
ISO 8879:1986 is the International
Organization for Standardization
(ISO) number for the
SGML standard, the predecessor (and a
superset) of XML.Otherwise, this string will either look like
-//Owner
or
+//Owner
(notice the only difference is the leading
+ or -).If the string starts with - then
the owner information is unregistered, with a
+ identifying it as
registered.ISO 9070:1991 defines how
registered names are generated. It might be derived
from the number of an ISO
publication, an ISBN code, or an
organization code assigned according to
ISO 6523. Additionally, a
registration authority could be created in order to
assign registered names. The ISO
council delegated this to the American National
Standards Institute (ANSI).Because the &os; Project has not been registered,
the owner string is -//&os;. As seen
in the example, the W3C are not a
registered owner either.KeywordThere are several keywords that indicate the type of
information in the file. Some of the most common
keywords are DTD,
ELEMENT, ENTITIES,
and TEXT. DTD is
used only for DTD files,
ELEMENT is usually used for
DTD fragments that contain only
entity or element declarations. TEXT
is used for XML content (text and
tags).DescriptionAny description can be given for the contents
of this file. This may include version numbers or any
short text that is meaningful and unique for the
XML system.LanguageAn ISO two-character code that
identifies the native language for the file.
EN is used for English.catalog FilesWith the syntax above, an XML
processor needs to have some way of turning the
FPI into the name of the file containing
the DTD. A catalog file (typically
called catalog) contains lines that map
FPIs to filenames. For example, if the
catalog file contained the line:PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "1.0/transitional.dtd"The XML processor knows that the
DTD is called
transitional.dtd in the
1.0 subdirectory of the directory that
held catalog.Examine the contents of
/usr/local/share/xml/dtd/xhtml/catalog.xml.
This is the catalog file for the XHTML
DTDs that were installed as part of the
textproc/docproj port.Alternatives to FPIsInstead of using an FPI to indicate the
DTD to which the document conforms (and
therefore, which file on the system contains the
DTD), the filename can be explicitly
specified.The syntax is slightly different:!DOCTYPE html SYSTEM "/path/to/file.dtd"The SYSTEM keyword indicates that the
XML processor should locate the
DTD in a system specific fashion. This
typically (but not always) means the DTD
will be provided as a filename.Using FPIs is preferred for reasons of
portability. If the SYSTEM identifier is
used, then the DTD must be provided and
kept in the same location for everyone.Escaping Back to XMLSome of the underlying XML syntax can be
useful within documents. For example, comments can be included
in the document, and will be ignored by the parser. Comments
are entered using XML syntax. Other uses for
XML syntax will be shown later.XML sections begin with a
<! tag and end with a
>. These sections contain instructions
for the parser rather than elements of the document. Everything
between these tags is XML syntax. The
DOCTYPE
declaration shown earlier is an example of
XML syntax included in the document.CommentsComments are an XML construct, and are
normally only valid inside a DTD. However,
as shows, it is possible
to use XML syntax within the document.The delimiter for XML comments is the string
--. The first occurrence of
this string opens a comment, and the second closes it.XML Generic Comment<!-- This is inside the comment -->
<!-- This is another comment -->
<!-- This is one way
of doing multiline comments -->
<!-- This is another way of --
-- doing multiline comments -->XHTML users may be familiar with different
rules for comments. In particular, it is often believed that
the string <!-- opens a comment, and it is
only closed by -->.This is not correct. Many web browsers
have broken XHTML parsers, and will accept
incorrect input as valid. However, the XML
parsers used by the Documentation Project are more strict, and
will reject documents with that error.Erroneous XML Comments<!-- This is in the comment --
THIS IS OUTSIDE THE COMMENT!
-- back inside the comment -->The XML parser will treat this as
though it were actually:<!THIS IS OUTSIDE THE COMMENT>That is not valid XML, and may give
confusing error messages.To Do…Add some comments to
example.xml, and check that the file
still validates using xmllint.Add some invalid comments to
example.xml, and see the error
messages that xmllint gives when it
encounters an invalid comment.EntitiesEntities are a mechanism for assigning names to chunks of
content. As an XML parser processes a
document, any entities it finds are replaced by the content of
the entity.This is a good way to have re-usable, easily changeable
chunks of content in XML documents. It is
also the only way to include one marked up file inside another
using XML.There are two types of entities for two different
situations: general entities and
parameter entities.General EntitiesGeneral entities are used to assign names to reusable
chunks of text. These entities can only be used in the
document. They cannot be used in an
XML context.To include the text of a general entity in the document,
include
&entity-name;
in the text. For example, consider a general entity called
current.version which expands to the
current version number of a product. To use it in the
document, write:paraThe current version of our product is
¤t.version;.paraWhen the version number changes, edit the definition of
the general entity, replacing the value. Then reprocess the
document.General entities can also be used to enter characters that
could not otherwise be included in an XML
document. For example, < and
& cannot normally appear in an
XML document. The XML
parser sees the < symbol as the start of
a tag. Likewise, when the & symbol is
seen, the next text is expected to be an entity name.These symbols can be included by using two predefined
general entities: < and
&.General entities can only be defined within an
XML context. Such definitions are usually
done immediately after the DOCTYPE declaration.Defining General Entities<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [
<!ENTITY current.version "3.0-RELEASE">
<!ENTITY last.version "2.2.7-RELEASE">
]>The DOCTYPE declaration has been extended by adding a
square bracket at the end of the first line. The two
entities are then defined over the next two lines, the
square bracket is closed, and then the DOCTYPE declaration
is closed.The square brackets are necessary to indicate that the
DTD indicated by the DOCTYPE declaration is being
extended.Parameter EntitiesParameter entities, like
general
entities, are used to assign names to reusable chunks
of text. But parameter entities can only be used within an
XML
context.Parameter entity definitions are similar to those for
general entities. However, parameter entries are included
with
%entity-name;.
The definition also includes the % between
the ENTITY keyword and the name of the
entity.For a mnemonic, think
Parameter entities use the
Percent symbol.Defining Parameter Entities<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [
<!ENTITY % param.some "some">
<!ENTITY % param.text "text">
<!ENTITY % param.new "%param.some more %param.text">
<!-- %param.new now contains "some more text" -->
]>To Do…Add a general entity to
example.xml.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [
<!ENTITY version "1.1">
]>
html xmlns="http://www.w3.org/1999/xhtml"headtitleAn Example XHTML Filetitlehead
<!-- There may be some comments in here as well -->
bodypThis is a paragraph containing some text.ppThis paragraph contains some more text.pp align="right"This paragraph might be right-justified.ppThe current version of this document is: &version;pbodyhtmlValidate the document using
xmllint.Load example.xml into a web
browser. It may have to be copied to
example.html before the browser
recognizes it as an XHTML
document.Older browsers with simple parsers may not render this
file as expected. The entity reference
&version; may not be replaced by
the version number, or the XML context
- closing ]< may not be recognized and
+ closing ]> may not be recognized and
instead shown in the output.The solution is to normalize the
document with an XML normalizer. The
normalizer reads valid XML and writes
equally valid XML which has been
transformed in some way. One way the normalizer
transforms the input is by expanding all the entity
references in the document, replacing the entities with
the text that they represent.xmllint can be used for this. It
also has an option to drop the initial
DTD section so that the closing
- ]< does not confuse browsers:
+ ]> does not confuse browsers:
&prompt.user; xmllint --noent --dropdtd example.xml > example.htmlA normalized copy of the document with entities
expanded is produced in example.html,
ready to load into a web browser.Using Entities to Include FilesBoth
general and
parameter
entities are particularly useful for including one file inside
another.Using General Entities to Include FilesConsider some content for an XML book
organized into files, one file per chapter, called
chapter1.xml,
chapter2.xml, and so forth, with a
book.xml that will contain these
chapters.In order to use the contents of these files as the values
for entities, they are declared with the
SYSTEM keyword. This directs the
XML parser to include the contents of the
named file as the value of the entity.Using General Entities to Include Files<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [
<!ENTITY chapter.1 SYSTEM "chapter1.xml">
<!ENTITY chapter.2 SYSTEM "chapter2.xml">
<!ENTITY chapter.3 SYSTEM "chapter3.xml">
<!-- And so forth -->
]>
html xmlns="http://www.w3.org/1999/xhtml"
<!-- Use the entities to load in the chapters -->
&chapter.1;
&chapter.2;
&chapter.3;
htmlWhen using general entities to include other files
within a document, the files being included
(chapter1.xml,
chapter2.xml, and so on)
must not start with a DOCTYPE
declaration. This is a syntax error because entities are
low-level constructs and they are resolved before any
parsing happens.Using Parameter Entities to Include FilesParameter entities can only be used inside an
XML context. Including a file in an
XML context can be used
to ensure that general entities are reusable.Suppose that there are many chapters in the document, and
these chapters were reused in two different books, each book
organizing the chapters in a different fashion.The entities could be listed at the top of each book, but
that quickly becomes cumbersome to manage.Instead, place the general entity definitions inside one
file, and use a parameter entity to include that file within
the document.Using Parameter Entities to Include FilesPlace the entity definitions in a separate file
called chapters.ent and
containing this text:<!ENTITY chapter.1 SYSTEM "chapter1.xml">
<!ENTITY chapter.2 SYSTEM "chapter2.xml">
<!ENTITY chapter.3 SYSTEM "chapter3.xml">Create a parameter entity to refer to the contents
of the file. Then use the parameter entity to load the file
into the document, which will then make all the general
entities available for use. Then use the general entities
as before:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [
<!-- Define a parameter entity to load in the chapter general entities -->
<!ENTITY % chapters SYSTEM "chapters.ent">
<!-- Now use the parameter entity to load in this file -->
%chapters;
]>
html xmlns="http://www.w3.org/1999/xhtml"
&chapter.1;
&chapter.2;
&chapter.3;
htmlTo Do…Use General Entities to Include FilesCreate three files, para1.xml,
para2.xml, and
para3.xml.Put content like this in each file:pThis is the first paragraph.pEdit example.xml so that it
looks like this:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [
<!ENTITY version "1.1">
<!ENTITY para1 SYSTEM "para1.xml">
<!ENTITY para2 SYSTEM "para2.xml">
<!ENTITY para3 SYSTEM "para3.xml">
]>
html xmlns="http://www.w3.org/1999/xhtml"headtitleAn Example XHTML FiletitleheadbodypThe current version of this document is: &version;p
¶1;
¶2;
¶3;
bodyhtmlProduce example.html by
normalizing example.xml.&prompt.user; xmllint --dropdtd --noent example.xml > example.htmlLoad example.html into the web
browser and confirm that the
paran.xml
files have been included in
example.html.Use Parameter Entities to Include FilesThe previous steps must have completed before this
step.Edit example.xml so that it
looks like this:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [
<!ENTITY % entities SYSTEM "entities.ent"> %entities;
]>
html xmlns="http://www.w3.org/1999/xhtml"headtitleAn Example XHTML FiletitleheadbodypThe current version of this document is: &version;p
¶1;
¶2;
¶3;
bodyhtmlCreate a new file called
entities.ent with this
content:<!ENTITY version "1.1">
<!ENTITY para1 SYSTEM "para1.xml">
<!ENTITY para2 SYSTEM "para2.xml">
<!ENTITY para3 SYSTEM "para3.xml">Produce example.html by
normalizing example.xml.&prompt.user; xmllint --dropdtd --noent example.xml > example.htmlLoad example.html into the web
browser and confirm that the
paran.xml
files have been included in
example.html.Marked SectionsXML provides a mechanism to indicate that
particular pieces of the document should be processed in a
special way. These are called
marked sections.Structure of a Marked Section<![KEYWORD[
Contents of marked section
]]>As expected of an XML construct, a marked
section starts with <!.The first square bracket begins the marked section.KEYWORD describes how this marked
section is to be processed by the parser.The second square bracket indicates the start of the
marked section's content.The marked section is finished by closing the two square
brackets, and then returning to the document context from the
XML context with
>.Marked Section KeywordsCDATAThese keywords denote the marked sections
content model, and allow you to change
it from the default.When an XML parser is processing a
document, it keeps track of the
content model.The content model describes the
content the parser is expecting to see and what it will do
with that content.The CDATA content model is one of the
most useful.CDATA is for
Character Data. When the parser is in this
content model, it expects to see only characters. In this
model the < and
& symbols lose their special status,
and will be treated as ordinary characters.When using CDATA in examples of
text marked up in XML, remember that
the content of CDATA is not validated.
The included text must be check with other means. For
example, the content could be written in another document,
validated, and then pasted into the
CDATA section.Using a CDATA Marked
SectionparaHere is an example of how to include some text that contains
many literal<literal and literal&literal
symbols. The sample text is a fragment of
acronymXHTMLacronym. The surrounding text (para and
programlisting) are from DocBook.paraprogramlisting<![CDATA[pThis is a sample that shows some of the
elements within acronymXHTMLacronym. Since the angle
brackets are used so many times, it is simpler to say the whole
example is a CDATA marked section than to use the entity names for
the left and right angle brackets throughout.pulliThis is a listitemliliThis is a second listitemliliThis is a third listitemliulpThis is the end of the example.p]]>programlistingINCLUDE and
IGNOREWhen the keyword is INCLUDE, then the
contents of the marked section will be processed. When the
keyword is IGNORE, the marked section
is ignored and will not be processed. It will not appear in
the output.Using INCLUDE and
IGNORE in Marked Sections<![INCLUDE[
This text will be processed and included.
]]>
<![IGNORE[
This text will not be processed or included.
]]>By itself, this is not too useful. Text to be
removed from the document could be cut out, or wrapped
in comments.It becomes more useful when controlled by
parameter
entities, yet this usage is limited
to entity files.For example, suppose that documentation was produced in
a hard-copy version and an electronic version. Some extra
text is desired in the electronic version content that was
not to appear in the hard-copy.Create an entity file that defines general entities to
include each chapter and guard these definitions with a
parameter entity that can be set to either
INCLUDE or IGNORE to
control whether the entity is defined. After these
conditional general entity definitions, place one more
definition for each general entity to set them to an empty
value. This technique makes use of the fact that entity
definitions cannot be overridden but the first definition
always takes effect. So the inclusion of the chapter is
controlled with the corresponding parameter entity. Set to
INCLUDE, the first general entity
definition will be read and the second one will be ignored.
Set to IGNORE, the first definition will
be ignored and the second one will take effect.Using a Parameter Entity to Control a Marked
Section<!ENTITY % electronic.copy "INCLUDE">
<![%electronic.copy;[
<!ENTITY chap.preface SYSTEM "preface.xml">
]]>
<!ENTITY chap.preface "">When producing the hard-copy version, change the
parameter entity's definition to:<!ENTITY % electronic.copy "IGNORE">To Do…Modify entities.ent to
contain the following:<!ENTITY version "1.1">
<!ENTITY % conditional.text "IGNORE">
<![%conditional.text;[
<!ENTITY para1 SYSTEM "para1.xml">
]]>
<!ENTITY para1 "">
<!ENTITY para2 SYSTEM "para2.xml">
<!ENTITY para3 SYSTEM "para3.xml">Normalize example.xml
and notice that the conditional text is not present in the
output document. Set the parameter entity
guard to INCLUDE and regenerate the
normalized document and the text will appear again.
This method makes sense if there are more
conditional chunks depending on the same condition. For
example, to control generating printed or online
text.ConclusionThat is the conclusion of this XML
primer. For reasons of space and complexity, several things
have not been covered in depth (or at all). However, the
previous sections cover enough XML to
introduce the organization of the FDP
documentation.