Tải bản đầy đủ (.pdf) (1,185 trang)

xml 1.1 bible 3rd edition

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (20.05 MB, 1,185 trang )

www.it-ebooks.info
XML 1.1 Bible
3rd Edition
Elliotte Rusty Harold
01 549863 FM.qxd 1/28/04 9:43 AM Page iii
www.it-ebooks.info
01 549863 FM.qxd 1/28/04 9:43 AM Page ii
www.it-ebooks.info
XML 1.1 Bible
3rd Edition
01 549863 FM.qxd 1/28/04 9:43 AM Page i
www.it-ebooks.info
01 549863 FM.qxd 1/28/04 9:43 AM Page ii
www.it-ebooks.info
XML 1.1 Bible
3rd Edition
Elliotte Rusty Harold
01 549863 FM.qxd 1/28/04 9:43 AM Page iii
www.it-ebooks.info
XML 1.1 Bible, 3rd Edition
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright  2004 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 0-7645-4986-3
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
3O/RT/QS/QU/IN


No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means,
electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of
the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through
payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923,
(978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Legal Department,
Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4447, E-Mail:

LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESENTATIONS
OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND
SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A
PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS.
THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS
SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR
OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT
PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR
DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS
A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE
PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS
IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE
CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ.
For general information on our other products and services or to obtain technical support, please contact our Customer
Care Department within the U.S. at (800) 762-2974, outside the U.S. at (317) 572-3993 or fax (317) 572-4002.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in
electronic books.
Library of Congress Control Number: 2004101453
Trademarks: Wiley and and the Wiley Publishing logo are trademarks or registered trademarks of John Wiley & Sons, Inc.
and/or its affiliates in the United States and other countries, and may not be used without written permission. All other
trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or
vendor mentioned in this book.
549863 FM.qxd 2/3/04 10:41 PM Page iv

www.it-ebooks.info
About the Author
Elliotte Rusty Harold is an internationally respected writer, programmer, and
educator, both on the Internet and off. He got his start writing FAQ lists for the
Macintosh newsgroups on Usenet and has since branched out into books, Web
sites, and newsletters. He’s an adjunct professor of computer science at
Polytechnic University in Brooklyn, New York. His Cafe con Leche Web site at
has become one of the most popular indepen-
dent XML sites on the Internet.
Elliotte is originally from New Orleans, to which he returns periodically in search of
a decent bowl of gumbo. However, he currently resides in the Prospect Heights
neighborhood of Brooklyn with his wife Beth, and his cats Charm (named after the
quark) and Marjorie (named after his mother-in-law). When not writing books, he
enjoys working on genealogy, mathematics, free software, and quantum mechanics.
His previous books include The Java Developer’s Resource, Java Network
Programming, Java Secrets, JavaBeans, Java I/O, XML: Extensible Markup Language,
XML in a Nutshell, Processing XML with Java, and Effective XML.
01 549863 FM.qxd 1/28/04 9:43 AM Page v
www.it-ebooks.info
Credits
Acquisitions Editor
Jim Minatel
Development Editor
Marcia Ellett
Technical Editor
David Schultz
Production Editor
Angela Smith
Copy Editor
Joanne Slike

Editorial Manager
Mary Beth Wakefield
Vice President & Executive Group
Publisher
Richard Swadley
Vice President and Executive
Publisher
Robert Ipsen
Vice President and Publisher
Joseph B. Wikert
Executive Editorial Director
Mary Bednarek
Project Coordinator
Erin Smith
Graphics and Production Specialists
Joyce Haughey
Jennifer Heleine
Kristin McMullan
Heather Ryan
Mary Gillot Virgin
Quality Control Technicians
Laura Albert
Susan Moritz
Carl William Pierce
Permissions Editor
Laura Moss
Media Development Specialist
Greg Stafford
Proofreading and Indexing
TECHBOOKS Production Services

01 549863 FM.qxd 1/28/04 9:43 AM Page vi
www.it-ebooks.info
Preface
W
elcome to the third edition of the XML 1.1 Bible. When the first edition was
published about five years ago, XML was a promising technology with a
small but growing niche. In the last half decade, it has absolutely exploded. XML no
longer needs to be justified as a good idea. In fact, the question developers are ask-
ing has changed from “Why XML?” to “Why not XML?” XML has become the data
format of choice for fields as diverse as stock trading and graphic design. More new
programs today are using XML than aren’t. A solid understanding of just what XML
is and how to use it has become a sine qua non for the computer literate.
The XML 1.1 Bible, 3rd Edition is your introduction to the exciting and fast-growing
world of XML. With this book, you’ll learn how to write documents in XML and how
to use style sheets to convert those documents into HTML so that legacy browsers
can read them. You’ll also learn how to use document type definitions (DTDs) and
schemas to describe and validate documents. You’ll encounter a variety of XML
applications in many domains, ranging from finance to vector graphics to geneal-
ogy. And you’ll learn how to take advantage of XML for your own unique projects,
programs, and web pages.
What’s New in the Third Edition
The French philosopher and mathematician Blaise Pascal once wrote in a letter, “I
have only made this longer because I have not had the time to make it shorter.” I
know how he felt. The first edition of the XML Bible was written under great time
pressure, was finished well after deadline, and totaled more than 1000 pages, the
largest book I had written up to that point. My favorite reader comment about that
edition was, “It would seem to me that if you asked the author to write 10,000 words
about the colour blue, he would be able to do it without breaking into a sweat.”
While I probably could write 10,000 words about blue, for the third edition, I did try
to restrain myself and take the time to write more concisely. I rewrote the book

from the ground up; and while I retained the basic flavor and outline that proved so
popular with the first edition, I tightened up the writing and cut many examples
down to size. With the benefit of five years of hindsight, I have also been able to
expand coverage of promising new technologies (schemas, XInclude, XHTML, SVG,
XML Base, and RDDL) while eliminating coverage of applications that proved to be
less useful than they initially appeared (WML, VML, CDF, HTML+TIME, RDF, and so
on). The result is a more concise, approachable volume that covers more of what
you need to know and less of what you don’t. If you liked the first or second edition,
you’re going to like the third edition even more. I’m confident you’ll find this an
even more useful tutorial and reference.
01 549863 FM.qxd 1/28/04 9:43 AM Page vii
www.it-ebooks.info
viii
Preface
Who You Are
Unlike most other XML books on the market, the XML 1.1 Bible, 3rd Edition dis-
cusses XML from the perspective of a web page author, not from the perspective of
a software developer. I don’t spend a lot of time discussing BNF grammars or pars-
ing element trees. Instead, I show you how you can use XML and existing tools
today to more efficiently produce attractive, exciting, easy-to-use, easy-to-maintain
web sites that keep your readers coming back for more.
This book is aimed directly at web site developers. I assume you want to use XML
to produce web sites that are difficult or impossible to create with raw HTML. You’ll
be amazed to discover that in conjunction with style sheets and a few free tools,
XML enables you to do things that previously required either custom software cost-
ing thousands of dollars per site or extensive knowledge of programming languages
such as Perl. None of the software discussed in this book will cost you more than a
few minutes of download time. None of the tricks require any programming.
What You Need to Know
XML does build on top of the underlying infrastructure of the Internet and the Web.

Consequently, I will assume you know how to FTP files, send e-mail, and load URLs
into your web browser of choice. I will also assume you have a reasonable knowl-
edge of HTML. On the other hand, when I discuss newer aspects of HTML that are
not yet in widespread use, such as Cascading Style Sheets, I discuss them in depth.
To be more specific, in this book I assume that you can do the following:
✦ Write a basic HTML page, including links, images, and text, using a text editor.
✦ Place that page on a web server.
On the other hand, I do not assume that you
✦ Know SGML. In fact, this preface is almost the only place in the entire book
you’ll see the word SGML used. XML is supposed to be simpler and more
widespread than SGML. It can’t be that if you have to learn SGML first.
✦ Are a programmer, whether of Java, Perl, C, or some other language. XML is a
markup language, not a programming language. You don’t need to be a pro-
grammer to write XML documents.
01 549863 FM.qxd 1/28/04 9:43 AM Page viii
www.it-ebooks.info
ix
Preface
What You’ll Learn
This book has one primary goal: to teach you to write XML documents for the Web.
Fortunately, XML has a decidedly flat learning curve, much like HTML (and unlike
SGML). As you learn a little, you can do a little. As you learn a little more, you can
do a little more. Thus, the chapters in this book build steadily on one another. They
are meant to be read in sequence. Along the way you’ll learn the following:
✦ How to author XML documents and deliver them to readers
✦ How semantic tagging makes XML documents easier to maintain and develop
than their HTML equivalents
✦ How to post XML documents on web servers in a form everyone can read
✦ How to make sure your XML is well formed
✦ How to write with international characters such as and Æ

✦ How to validate documents against DTDs and schemas
✦ How to build large documents from smaller parts using entities and XInclude
✦ How to merge different XML vocabularies with namespaces
✦ How to format your documents with CSS and XSL style sheets
✦ How to connect documents with XLinks and XPointers
In the final part of this book, you’ll see several practical examples of XML being
used for real-world applications, including the following:
✦ Web site design
✦ Schemas
✦ Vector graphics
✦ Genealogy
How the Book Is Organized
This book is divided into five parts:
I. Introducing XML
II. Document Type Definitions
III. Style Languages
IV. Supplemental Technologies
V. XML Applications
01 549863 FM.qxd 1/28/04 9:43 AM Page ix
www.it-ebooks.info
x
Preface
By the time you finish reading this book, you’ll be ready to use XML to create com-
pelling web pages.
Part I: Introducing XML
Part I (Chapters 1 through 6) begins with the history and theory behind XML and
the goals XML is trying to achieve. It shows you how the different pieces of the XML
equation fit together to enable you to create and deliver documents to readers.
You’ll see several compelling examples of XML applications to give you some idea
of the wide applicability of XML, including Scalable Vector Graphics (SVG), the

Open Financial Exchange (OFX), the Mathematical Markup Language (MathML), the
Extensible Forms Description Language (XFDL), and many others. Then you’ll learn
by example how to write XML documents with tags that you define that make sense
for your document. You’ll learn how to edit them in a text editor, attach style sheets
to them, and load them into a web browser such as Internet Explorer 5.0 or Mozilla.
Part II: Document Type Definitions
Part II (Chapters 7 through 11) focuses on document type definitions (DTDs). A
DTD specifies which elements are and are not allowed in an XML document, and the
exact context and structure of those elements. A validating parser can read a docu-
ment, compare it to its DTD, and report any mistakes it finds. DTDs enable docu-
ment authors to ensure that their work meets any necessary criteria.
In Part II, you’ll learn how to attach a DTD to a document, how to validate your doc-
uments against their DTDs, and how to write new DTDs that solve your own prob-
lems. You’ll learn the syntax for declaring elements, attributes, entities, and
notations. You’ll learn how to use entity declarations and entity references to build
both a document and its DTD from multiple, independent pieces. This allows you to
make long, hard-to-follow documents much simpler by separating them into related
modules and components. And you’ll learn how to use namespaces to mix together
different XML vocabularies in one document.
Part III: Style Languages
Part III (Chapters 12 through 16) teaches you everything you need to know about
style sheets. XML markup only specifies what’s in a document. Unlike HTML, it does
not say anything about what that content should look like. Instead, style shheets
provide all necessary information about an XML document’s appearance when
printed, viewed in a web browser, or otherwise displayed. Different style sheets can
be applied to the same document. You might, for example, want to use one style
sheet that specifies small fonts for printing, another one with larger fonts for on-
screen presentation, and a third with absolutely humongous fonts to project the
document on a wall at a seminar. You can change the appearance of an XML docu-
ment by choosing a different style sheet without touching the document itself.

01 549863 FM.qxd 1/28/04 9:43 AM Page x
www.it-ebooks.info
xi
Preface
Part III describes in detail the two style sheet languages in broadest use today,
Cascading Style Sheets (CSS) and the Extensible Stylesheet Language (XSL). CSS is a
simple style sheet language originally designed for use with HTML. It applies fixed
style rules to the contents of particular elements.
XSL, by contrast, is a more complicated and more powerful style language that can
apply styles to the contents of elements, as well as rearrange elements, add boiler-
plate text, and transform documents in almost arbitrary ways. XSL is divided into
two parts: a transformation language for converting XML trees to alternative trees,
and a formatting language for specifying the appearance of the elements of an
XML tree.
Part IV: Supplemental Technologies
Part IV (Chapters 17 through 20) introduces some XML-based languages and syn-
taxes that layer on top of basic XML to provide additional functionality and fea-
tures. XLink provides multidirectional hypertext links that are far more powerful
than the simple HTML
<A> tag. XPointers introduce a new syntax you can attach to
the end of URLs to link not only to particular documents but also to particular parts
of particular documents. XInclude enables you to build large XML documents out of
multiple smaller XML documents. XML Schemas provide a more complete valida-
tions language that includes data typing and range checking. All of these can be
added to your own XML-based markup languages to extend their power and utility.
Part V: XML Applications
Part V (Chapters 21 to 25) demonstrates several practical uses of XML in different
domains. XHTML is a reformulation of HTML 4.0 as valid XML. RDDL is an XHTML-
and XLink-based language for documents containing meta-information placed at the
end of namespace URLs. Scalable Vector Graphics (SVG) is a standard XML format

for drawings recommended by the World Wide Web Consortium (W3C). Finally, a
completely new application is developed for genealogical data to show you not just
how to use XML tags and technologies, but why and when to choose them.
Combining all of these different applications, you’ll develop a good sense of how
XML applications are designed, built, and used in the real world.
What You Need
XML is a platform-independent technology. You’ll notice that screen shots in this
book have been captured from Windows, Mac OS 9, Mac OS X, and Linux. Almost all
the examples work equally well across all common platforms. You will need a web
browser that supports XML, such as Mozilla, Netscape 6.0 or later, or Internet
Explorer 6.0.
01 549863 FM.qxd 1/28/04 9:43 AM Page xi
www.it-ebooks.info
xii
Preface
Furthermore, much of the best software for working with XML is written in Java and
can run on multiple platforms. Much of this is freely available on the Internet. You
will need a Java 1.2 or later virtual machine. (Java 1.1 can do in a pinch.) You won’t
need to write any programs to use this book. You’ll just need it to run programs
written in Java.
How to Use This Book
This book is designed to be read more or less cover to cover. Each chapter builds
on the material in the previous chapters in a fairly predictable fashion. Of course,
you’re always welcome to skim over material that’s already familiar to you. I also
hope you’ll stop along the way to try out some of the examples and to write some
XML documents of your own. It’s important to learn not just by reading, but also by
doing. Before you get started, I’d like to make a couple of notes about grammatical
conventions used in this book.
Unlike HTML, XML is case-sensitive.
<FATHER> is not the same as <Father> or

<father>. The father element is not the same as the Father element or the
FATHER element. Unfortunately, case-sensitive markup languages have an annoying
habit of conflicting with standard English usage. On rare occasion, this means that
you may encounter sentences that don’t begin with a capital letter. More commonly,
you’ll see capitalization used in the middle of a sentence where you wouldn’t
normally expect it. Please don’t get too bothered by this. All XML and HTML code
used in this book is placed in a
monospaced font, so most of the time it will be
obvious from the context what is meant.
I have also adopted the British convention of placing punctuation inside quote
marks only when it belongs with the material quoted. Frankly, although I learned to
write in the American educational system, I find the British system far more logical,
especially when dealing with source code where the difference between a comma
or a period and no punctuation at all can make the difference between perfectly
correct and perfectly incorrect code.
What the Icons Mean
Throughout the book, I’ve used icons in the left margin to call your attention to
points that are particularly important.
Note icons provide supplemental information about the subject at hand, but gen-
erally something that isn’t quite the main idea. Notes are often used to elaborate
on a detailed technical point.
Note
01 549863 FM.qxd 1/28/04 9:43 AM Page xii
www.it-ebooks.info
xiii
Preface
Tip icons indicate a more efficient way of doing something, or a technique that may
not be obvious.
Caution icons warn you of a common misconception or that a procedure doesn’t
always work quite like it’s supposed to. The most common reason for a Caution

icon in this book is to point out the difference between what a specification says
should happen and what actually does.
The Cross-Reference icon refers you to other chapters that have more to say about
a particular subject.
Reach Out
Feedback on past editions has had a significant positive effect on the structure and
content of this edition, and I encourage you to let me know what you think of it so I
can continue to improve future editions. After you have had a chance to read this
book, please take a moment to send me an e-mail at
Be
sure to include the title of this book in your e-mail. Please be honest in your evalua-
tion. If you thought a particular chapter didn’t tell you enough, let me know. Of
course, I would prefer to receive comments such as “This is the best book I’ve ever
read,” “Thanks to this book, my web site won Cool Site of the Year,” or “Because I
was reading this book on the beach, I met a stunning swimsuit model who thought I
was the hottest thing on feet,” but I’ll take any comments I can get.
J
You should also feel free to send me specific questions regarding the material in
this book. I’ll do my best to help you out and answer your questions, but I can’t
guarantee a reply. Generally, more specific questions (How do I change the value of
a variable in XSLT?) are more likely to receive timely, useful answers than very
generic, broad questions (How is XML used in the legal profession?).
Also, I invite you to visit my Cafe con Leche web site at
econleche.
org
, which contains a lot of XML-related material and is updated almost daily. Despite
my persistent efforts to make this book perfect, some errors have doubtless slipped
by. Even more certainly, some of the material discussed here will change over time. I’ll
post any necessary updates and errata on my web site at
econleche.

org/books/bible3/
. Please let me know via e-mail of any errors that you find that
aren’t already listed.
I hope you enjoy the book. Happy XMLing!
Elliotte Rusty Harold


New York City, December 11, 2003
Cross-
Reference
Caution
Tip
01 549863 FM.qxd 1/28/04 9:43 AM Page xiii
www.it-ebooks.info
01 549863 FM.qxd 1/28/04 9:43 AM Page xiv
www.it-ebooks.info
Acknowledgments
T
he folks at Wiley Publishing have all been great. The acquisitions editors, John
Osborn, Grace Buechlein on the second edition, and Jim Minatel on this edi-
tion deserve special thanks for arranging the unusual scheduling this book required
to hit the moving target that XML presents. Marcia Ellett shepherded this book
through the development process. She managed the shifting outline and schedule
that a book based on unstable specifications and software requires with poise and
grace. Angela Smith proved equally adept on shepherding this book through its
final production. Terri Varveris edited the first edition and Sharon Nash the second
edition. Without them, there could never have been a third edition.
Steven Champeon brought his SGML experience to the book, and provided many
insightful comments on the text. My brother, Thomas Harold, put his command of
chemistry at my disposal when I was trying to grasp the Chemical Markup

Language. Carroll Bellau provided me with the parts of my family tree, which you’ll
find in Chapter 18. Piroz Mohseni and Heather Williamson served as technical edi-
tors on the first edition and corrected many of my errors. Ken Cox performed the
same service for the second edition, and B.K. Delong for the Gold edition. David
Schultz stepped up to the plate for this edition.
I also greatly appreciate all the comments, questions, and corrections sent in by
readers of the first and second editions and XML: Extensible Markup Language. I
hope that I’ve managed to address most of those comments in this book. They’ve
definitely helped make the XML 1.1 Bible, 3rd Edition a better book. Particular
thanks are due to Michael Dyck, Alan Esenther, and Donald Lancon, Jr. for their
especially detailed comments.
The agenting talents of David and Sherry Rogelberg of the Studio B Literary Agency
(
have made it possible for me to write effectively full-
time. I recommend them highly to anyone thinking about writing computer books.
And, as always, thanks go to my wife, Beth, for her endless love and understanding.
01 549863 FM.qxd 1/28/04 9:43 AM Page xv
www.it-ebooks.info
Contents at a Glance
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Part I: Introducing XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Chapter 1: An Eagle’s Eye View of XML . . . . . . . . . . . . . . . . . . . . . . . . . 3
Chapter 2: XML Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Chapter 3: Your First XML Document . . . . . . . . . . . . . . . . . . . . . . . . . 55
Chapter 4: Structuring Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Chapter 5: Attributes, Empty-Element Tags, and XSL . . . . . . . . . . . . . . . . 103
Chapter 6: Well-formedness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Part II: Document Type Definitions . . . . . . . . . . . . . . . . . . . . 187
Chapter 7: Validity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189

Chapter 8: Element Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Chapter 9: Attribute Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
Chapter 10: Entity Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Chapter 11: Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
Part III: Style Languages . . . . . . . . . . . . . . . . . . . . . . . . . . 309
Chapter 12: CSS Style Sheets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
Chapter 13: CSS Layouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
Chapter 14: CSS Text Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
Chapter 15: XSL Transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
Chapter 16: XSL Formatting Objects . . . . . . . . . . . . . . . . . . . . . . . . . 507
01 549863 FM.qxd 1/28/04 9:43 AM Page xvi
www.it-ebooks.info
Part IV: Supplemental Technologies . . . . . . . . . . . . . . . . . . . 577
Chapter 17: XLinks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579
Chapter 18: XPointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617
Chapter 19: XInclude . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 647
Chapter 20: Schemas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 667
Part V: XML Applications . . . . . . . . . . . . . . . . . . . . . . . . . . 731
Chapter 21: XHTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 733
Chapter 22: Modular XHTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 787
Chapter 23: The Resource Directory Description Language . . . . . . . . . . . . 833
Chapter 24: Scalable Vector Graphics . . . . . . . . . . . . . . . . . . . . . . . . . 849
Chapter 25: Designing a New XML Application . . . . . . . . . . . . . . . . . . . 907
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 983
01 549863 FM.qxd 1/28/04 9:43 AM Page xvii
www.it-ebooks.info
01 549863 FM.qxd 1/28/04 9:43 AM Page xviii
www.it-ebooks.info
Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii

Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Part I: Introducing XML 1
Chapter 1: An Eagle’s Eye View of XML . . . . . . . . . . . . . . . . . . . 3
What Is XML? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
XML is a meta-markup language . . . . . . . . . . . . . . . . . . . . . . 3
XML describes structure and semantics, not formatting . . . . . . . . 5
Why Are Developers Excited About XML? . . . . . . . . . . . . . . . . . . . . 6
Domain-specific markup languages . . . . . . . . . . . . . . . . . . . . . 6
Self-describing data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Interchange of data among applications . . . . . . . . . . . . . . . . . . 8
Structured data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
The Life of an XML Document . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Parsers and processors . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Browsers and other applications . . . . . . . . . . . . . . . . . . . . . 10
The process summarized . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Related Technologies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
CSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
XSL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
URLs and URIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
XLinks and XPointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Unicode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Putting the pieces together . . . . . . . . . . . . . . . . . . . . . . . . . 15
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Chapter 2: XML Applications . . . . . . . . . . . . . . . . . . . . . . . . 17
What Is an XML Application? . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Chemical Markup Language . . . . . . . . . . . . . . . . . . . . . . . . 18
Mathematical Markup Language . . . . . . . . . . . . . . . . . . . . . . 19
RSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

Classic literature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Synchronized Multimedia Integration Language . . . . . . . . . . . . . 26
01 549863 FM.qxd 1/28/04 9:43 AM Page xix
www.it-ebooks.info
xx
Contents
Open Software Description . . . . . . . . . . . . . . . . . . . . . . . . . 26
Scalable Vector Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . 27
MusicXML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
VoiceXML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Open Financial Exchange . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Extensible Forms Description Language . . . . . . . . . . . . . . . . . 36
HR-XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
XML for XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
XSL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
XLinks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Schemas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Behind-the-Scene Uses of XML . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Microsoft Office 2003 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Netscape’s What’s Related . . . . . . . . . . . . . . . . . . . . . . . . . 49
UPS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Chapter 3: Your First XML Document . . . . . . . . . . . . . . . . . . . 55
Hello XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Creating a simple XML document . . . . . . . . . . . . . . . . . . . . . 56
Saving the XML file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Loading the XML file into a web browser . . . . . . . . . . . . . . . . . 57
Exploring the Simple XML Document . . . . . . . . . . . . . . . . . . . . . . 58
Meaning in Markup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Writing a Style Sheet for an XML Document . . . . . . . . . . . . . . . . . . 60

Attaching a Style Sheet to an XML Document . . . . . . . . . . . . . . . . . 61
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Chapter 4: Structuring Data . . . . . . . . . . . . . . . . . . . . . . . . . 63
Examining the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
XMLizing the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
The Advantages of the XML Format . . . . . . . . . . . . . . . . . . . . . . . 87
Preparing a Style Sheet for Document Display . . . . . . . . . . . . . . . . . 88
Linking to a style sheet . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Assigning style rules to the root element . . . . . . . . . . . . . . . . . 90
Assigning style rules to titles . . . . . . . . . . . . . . . . . . . . . . . 91
The complete style sheet . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Chapter 5: Attributes, Empty-Element Tags, and XSL . . . . . . . . . 103
Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Attributes versus Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Structured metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Meta-metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
01 549863 FM.qxd 1/28/04 9:43 AM Page xx
www.it-ebooks.info
xxi
Contents
What’s your metadata is someone else’s data . . . . . . . . . . . . . 113
Elements are more extensible . . . . . . . . . . . . . . . . . . . . . . 114
Good times to use attributes . . . . . . . . . . . . . . . . . . . . . . . 114
Empty Elements and Empty-Element Tags . . . . . . . . . . . . . . . . . . . 116
XSL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
The body of the document . . . . . . . . . . . . . . . . . . . . . . . . 121
The title . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Stations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126

Shows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
CSS or XSL? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Chapter 6: Well-formedness . . . . . . . . . . . . . . . . . . . . . . . . 145
Well-formedness Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
XML Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
The XML declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Single root element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Text in XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Elements and Tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Element names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Every start-tag must have a corresponding end-tag . . . . . . . . . . 150
Empty-element tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Elements may nest but may not overlap . . . . . . . . . . . . . . . . 152
Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Attribute names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Attribute values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Predefined attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Entity References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Processing Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
CDATA Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Unicode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Character encodings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
The encoding declaration . . . . . . . . . . . . . . . . . . . . . . . . . 168
Numeric character references . . . . . . . . . . . . . . . . . . . . . . 169
XML 1.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Well-formed HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173

Rules for HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
01 549863 FM.qxd 1/28/04 9:43 AM Page xxi
www.it-ebooks.info
xxii
Contents
Part II: Document Type Definitions 187
Chapter 7: Validity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Document Type Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Element Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
DTD Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
Document Type Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . 192
Internal DTDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Internal and external DTD subsets . . . . . . . . . . . . . . . . . . . . 195
Public DTDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
DTDs and style sheets . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Validating against a DTD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Command-line validators . . . . . . . . . . . . . . . . . . . . . . . . . 200
Web-based validators . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Chapter 8: Element Declarations . . . . . . . . . . . . . . . . . . . . . 205
Analyzing the Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
ANY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
#PCDATA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
Child Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
+ One or More Children . . . . . . . . . . . . . . . . . . . . . . . . . . 215
? Zero or One Child . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
* Zero or More Children . . . . . . . . . . . . . . . . . . . . . . . . . . 216
Choices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216

Parentheses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Mixed Content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Empty Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Comments in DTDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Chapter 9: Attribute Declarations . . . . . . . . . . . . . . . . . . . . 229
What Is an Attribute? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
Declaring Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Declaring Multiple Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Alternatives to Default Attribute Values . . . . . . . . . . . . . . . . . . . . 232
#REQUIRED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
#IMPLIED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
#FIXED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Attribute Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
The CDATA attribute type . . . . . . . . . . . . . . . . . . . . . . . . . 235
The NMTOKEN attribute type . . . . . . . . . . . . . . . . . . . . . . 236
01 549863 FM.qxd 1/28/04 9:43 AM Page xxii
www.it-ebooks.info

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×