Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Welcome to Real World XML. This book is designed to be as comprehensive—and as accessible—as possible for a single book on XML. XML is a standard, not an implementation, and it's become an umbrella for a great number of topics. You'll find XML just about everywhere you look on the Internet today, and even in many places behind the scenes (such as internally in Netscape Navigator 6). I believe this book provides more complete coverage of what's going on in XML than any other XML book today.
You'll find coverage of all the official XML standards here. I'll also take a look at many of the most popular and important implementations of XML that are out there, and put them to work in this book.
That's just part of the story—we'll also put XML to work in depth, pushing the envelope as far as it can go. The best way to learn any topic like XML is by example, and this is an example-oriented book. You'll find hundreds of tested examples here, ready to be used.
Writing XML is not some ordinary and monotonous task: it inspires artistry, devotion, passion, exaltation, and eccentricity—not to mention exasperation and frustration. I'll try to be true to that spirit and capture as much of the excitement and power of XML in this book as I can.
This book is designed to give you as much of the whole XML story as one book can hold. We'll not only see the full XML syntax—from the most basic to the most advanced—but also dig into many of the ways in which XML is used.
There are hundreds of real-world topics covered in this book, like connecting XML to databases—both locally and on Web servers—styling XML for viewing in today's browsers, reading and using XML documents in browsers, creating our own graphically based browsers, and a great deal more.
Here's a sample of some of the topics in this book—note that each of these topics themselves have many subtopics (too many to list here):
The complete XML syntax
Well-formed XML documents
Valid XML documents
Document type definitions (DTDs)
Namespaces
The XML Document Object Model (DOM)
Canonical XML
XML schemas
Parsing XML with JavaScript
XML and data binding
XML and Cascading Style Sheets (CSS)
XML and Java
XML and .NET
DOM parsers
SAX parsers
Extensible Stylesheet Language (XSL) transformations
XSL formatting objects
XLinks
XPointers
XPath
XBase
XHTML 1.0 and 1.1
Resource Description Framework (RDF)
Simple Object Access Protocol (SOAP)
Vector Markup Language (VML)
Wireless Markup Language (WML)
Server-side XML with JavaServer Pages (JSP), Active Server Pages (ASP), Java servlets, and Perl
This book starts with the basics. I do assume that you have some knowledge of HTML, but not necessarily much. We'll see how to create XML documents from scratch in this book, starting at the very beginning.
From there, we'll move up to see how to check the syntax of XML documents. The big attraction of XML is that you can define your own tags, like the <DOCUMENT> and <GREETING> tags in this document, which we'll see early in Chapter 1:
<?xml version="1.0" encoding="UTF-8"?>
<DOCUMENT>
<GREETING>
Hello From XML
</GREETING>
<MESSAGE>
Welcome to the wild and woolly world of XML.
</MESSAGE>
</DOCUMENT>
Because you can create your own tags in XML, it's also important to specify the syntax you want those tags to obey (for example, can a <MESSAGE> appear inside a <GREETING>?). XML puts a big emphasis on this, too, and there are two main ways to specify the syntax you want your XML to follow—with XML document type definitions (DTDs) and XML schemas. We'll see how to create both.
And because you can make up your own tags in XML, it's also up to you to specify how they should be used—Netscape Navigator won't know, for example, that a <KILLER> tag marks a favorite book in your collection. Because it's up to you to determine what a tag actually means, handling your XML documents in programming is an important part of learning XML, despite what some second-rate XML books try to claim. The two languages I'll use in this book are JavaScript and Java; before using them, I'll introduce them in special sections with plenty of examples, so even if you're not familiar with these languages, you won't have to go anywhere else to get the skills you need.
The major browsers today are becoming more and more XML-aware, and they use scripting languages to let you work with your XML documents. We'll be using the most popular and powerful of those scripting languages here, JavaScript. Using JavaScript, we'll be able to read XML documents directly in browsers like the Microsoft Internet Explorer.
It's also important to know how to handle XML outside browsers, because there are plenty of things that JavaScript can't handle. These days, most XML development is taking place in Java, and there is an endless arsenal of Java resources available for free on the Internet. In fact, the connection between Java and XML is a natural one, as we'll see. We'll use Java to read XML documents and interpret them, starting in Chapter 11. That doesn't mean you have to be a Java expert—far from it, in fact—because I'll introduce all the Java we'll need right here in this book. And because most XML development is done in Java today, we're going to find a wealth of tools here, ready for use.
You can also design your XML documents to be displayed directly in some modern browsers, and I'll take a look at doing that in two ways—with Cascading Style Sheets (CSS) and the Extensible Stylesheet Language (XSL). Using CSS and XSL, you can indicate exactly how a tag that you make up, like <PANIC> or <BIG_AND_BOLD> or <AZURE_UNDERLINED_TEXT>, should be displayed. I'll take a look at both parts of XSL—XSL transformations and formatting objects—in depth.
In addition, we'll see various other XML specifications in this book as well, such as XLinks, XBase, and XPointers, which let you point to particular items in XML documents in very specific ways. The XML specifications are made by a body called the World Wide Web Consortium, abbreviated W3C, and we'll become very familiar with those specifications here, seeing what they say—and seeing what they lack.
I'll wind up the book by taking a look at a number of the most popular uses of XML on the Internet in several chapters. XML is really a language for defining languages, and there are hundreds of such XML-based languages out there now. Some of them are gaining great popularity, and I'll cover them in some depth in this book.
There is an astonishing wealth of material on XML available on the Internet today, so I'm also going to fill this book with the URIs of dozens of those resources (in XML, you use Uniform Resource Identifiers, not URLs, although in practice they are the same thing for most purposes today). In nearly every chapter, you'll find lists of free online programs and other resources. (However, there's a hazard here that I should mention—URIs change frequently on the Internet, so don't be surprised if some of these URIs have changed by the time you look for them.)
This book is designed for just about anyone who wants to learn XML and how it's used today in the real world. The only assumption that I make is that you have some knowledge of how to create documents using Hypertext Markup Language (HTML). You don't have to be any great HTML expert, but a little knowledge of HTML will be helpful. That's really all you need.
However, it's a fact of life that most XML software these days is targeted at Windows. Among other things, this means you should have access to Windows for many of the topics covered in this book, and in Chapters 7 and 8, we'll be taking a look at the XML support in Microsoft Internet Explorer. I wish there was more support for the other operating systems I like, such as Unix, but right now a lot of it is Windows-only. I'll explore alternatives when I can. One hopeful note for the future is that there are more and more Java-based XML tools appearing daily, and those tools are platform-independent.
This book is written at several different levels—from basic to advanced—because the XML spectrum is so broad. The rule of thumb is that this book was written to follow HTML books in level. We start at the basic level and gradually get more advanced in a slow, steady way.
I'm not going to assume that you have any programming knowledge (at least until we get to the advanced topics in Chapter 20, such as JavaServer Pages and using Perl with XML) when you start this book. We'll be using both JavaScript and Java in this book, but all you need to know about those languages will be introduced before we use them, and it won't be hard to pick up.
Because there are so many uses of XML available today, this book involves many different software packages; all the ones I'll put to work in the text are free to download from the Internet; I'll tell you where to get them.
There are several conventions that I use in this book that you should be aware of. The most important one is that when I add new sections of code, I'll mark them with gray highlighting to point out the actual lines I'm discussing so that they stand out. (This sample is written in one of the languages built on XML, the Wireless Markup Language (WML), which is targeted at “micro-browsers” in cellular phones and personal digital assistants, or PDAs.)
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="Card1" title="First WML Example">
<!-- This is a comment -->
<p>
Greetings from WML.
</p>
</card>
</wml>
Also, where there's something worth noting or some additional information that adds something to the discussion, I'll add a sidebar:
More on SOAPWith a common name like SOAP, it's hard to search the Internet for more information about the Simple Object Access Protocol unless you're really into pages on personal cleanliness and daytime television. For more information, you might check out this starter list: http://msdn.microsoft.com/xml/general/soapspec.asp, www.oasis-open.org/cover/soap.html, www.develop.com/soap/, and www.develop.com/soap/soapfaq.xml. |
Well, we're ready to go. If you have comments, I encourage you to write to me, care of New Riders. This book is designed to be the new standard in XML coverage, truly more complete and more accessible than ever before. Please do keep in touch with me with ways to improve it and keep it on the forefront. If you think the book lacks anything, let me know—I'll add it, because I want to make sure this book stays on top.