Part I: Introduction

Chapter 1: What is XML?

Of Data, Files, and Text

So What Is XML?

Origin of the XML Standards

Where XML Can Be Used, and What You Can Use It For

Summary

Exercise Questions

Chapter 2: Well-Formed XML

Parsing XML

Tags and Text and Elements, Oh My!

Attributes

Comments

Empty Elements

XML Declarations

Processing Instructions

Illegal PCDATA Characters

Errors in XML

Summary

Exercise Questions

Chapter 3: XML Namespaces

Why We Need Namespaces

How XML Namespaces Work

Understanding URIs

When to Use Namespaces

Summary

Exercise Questions

Part II: Validation

Chapter 4: Document Type Definitions

Running the Samples

Sharing Vocabularies

Anatomy of a DTD

Developing DTDs

DTD Limitations

Summary

Exercise Questions

Chapter 5: XML Schemas

Benefits of XML Schemas

Do We Still Need DTDs?

XML Schemas

Creating a Schema from Multiple Documents

Documenting XML Schemas

Summary

Exercise Questions

Chapter 6: Relax Ng

XML and Compact Syntaxes

RELAX NG Patterns

Combining and Reusing Patterns and Grammars

Additional RELAX NG Features

Useful Resources

Summary

Exercise Questions

Part III: Processing

Chapter 7: XPath

Ways of Looking at an XML Document

Modeling XML Documents

Visualizing XPath

Abbreviated and Unabbreviated Syntax

XPath 1.0 Axes

XPath 1.0 Functions

Predicates

Structure of XPath Expressions

XPath 2.0

Summary

Exercises Questions

Chapter 8: XSLT

What Is XSLT?

How an XSLT Processor Works

Running the Examples

Procedural versus Declarative Programming

Foundational XSLT Elements

Getting Information from the Source Tree

Influencing the Output with the <xsl:output> Element

Conditional Processing

The <xsl:for-each> Element

The <xsl:sort> Element

XSLT Modes

XSLT Variables and Parameters

Named Templates and the <xsl:call-template> Element

XSLT Functions

XSLT 2.0

Summary

Exercise Questions

Part IV: Databases

Chapter 9: XQuery, the XML Query Language

Why XQuery?

XQuery Tools

Some XQuery Examples

The XQuery Data Model

XQuery Expressions

XQuery Functions

Using Parameters with XQuery

User-Defined Functions

Looking Ahead

Summary

Exercise Questions

Chapter 10: XML and Databases

The Need for Efficient XML Data Stores

Approaches to Storing XML

Using Native XML Databases

XML in Commercial RDBMSs

XML in Open Source RDBMS

Choosing a Database to Store XML

Looking Ahead

Summary

Exercise Questions

Part V: Programming

Chapter 11: The XML Document Object Model (DOM)

Purpose of the XML DOM

The Document Object Model at the W3C

Two Ways to View DOM Nodes

Tools to Run the Examples

The Node Object

The Document Interface

How the XML DOM Is Used in InfoPath 2007

Summary

Exercise Questions

Chapter 12: Simple API for XML (SAX)

What Is SAX and Why Was It Invented?

Receiving SAX Events

Good SAX and Bad SAX

Consumers, Producers, and Filters

Other Languages

Summary

Exercise Questions

Part VI: Communication

Chapter 13: RSS, Atom, and Content Syndication

Syndication and Meta Data

Working with News Feeds

A Simple Aggregator

Useful Resources

Summary

Exercise Questions

Chapter 14: Web Services

What Is an RPC?

RPC Protocols

The New RPC Protocol: Web Services

Taking a REST

The Web Services Stack

Summary

Exercise Questions

Chapter 15: SOAP and WSDL

Laying the Groundwork

Running Examples in Windows 2003, XP, and 2000

The New RPC Protocol: SOAP

Defining Web Services: WSDL

Summary

Exercise Questions

Chapter 16: Ajax

Early Attempts at Asynchronous Updates

Basic Posting Techniques

Transport and Processing on the Server

Server-Side Proxies

Summary

Exercise Questions

Part VII: Display

Chapter 17: Cascading Style Sheets (CSS)

Why Stylesheets?

Introducing CSS

Using CSS for Layout of XML Documents

Laying Out Tabular Data

Links in XML Documents

Images in XML Documents

Using CSS to Add Content to Documents

Attribute Content

Summary

Exercise Questions

Chapter 18: XHTML

Separating Style from Content

Learning XHTML 1.x

Modularized XHTML

What's Next for XHTML

Summary

Exercise Questions

Chapter 19: Scalable Vector Graphics (SVG)

What Is SVG?

Getting Started

Tangram: A Simple Application

Useful Resources

Summary

Exercise Questions

Chapter 20: XForms

How XForms Improves on HTML Forms

XForms Tools

An Illustrative XForms Example

XForms Form Controls

Constraining XForms Instances

XForms Events

The XForms Action Module

Alternatives to XForms

Summary

Exercise Questions

Part VIII: Case Study

Chapter 21: Case Study: Payment Calculator

Mortgage Calculations

What You'll Need

Online Loan Calculator

Summary

Chapter 22: Case Study: Payment Calculator—Ruby on Rails

Mortgage Calculations

What You Need for the Example

Creating the Project

Building the Online Loan Calculator

Summary

Appendix A: Exercise Solutions

Chapter 1

Chapter 2

Chapter 3

Chapter 4

Chapter 5

Chapter 6

Chapter 7

Chapter 8

Chapter 9

Chapter 10

Chapter 11

Chapter 12

Chapter 13

Chapter 14

Chapter 15

Chapter 16

Chapter 17

Chapter 18

Chapter 19

Chapter 20

Appendix B: XPath Reference

XPath 2.0 Is Emerging Slowly

Node Tests

Functions

Appendix C: XSLT Reference

Elements

Functions

New in XSLT 2.0

Planning on Using XSLT 2.0

A Quick Note on XSLT 2.0 and XQuery 1.0

Appendix D: The XML Document Object Model

Notation

Basic Datatypes

Fundamental Interfaces: Core Module

Extended Interfaces: XML Module

Load and Save Interfaces

Validation Interfaces

Appendix E: XML Schema Element and Attribute Reference

XML Schema Instance Attributes

Appendix F: XML Schema Datatypes Reference

XML Schema Built-in Datatypes

Constraining Facets

Appendix G: SAX 2.0.2 Reference

Classes and Interfaces

Introduction

Who Is This Book For?

How This Book Is Organized

What's Covered in This Book

What You Need to Use This Book

Conventions

Source Code

Errata

p2p.wrox.com

Part I

Introduction

Chapter 1: What Is XML?

Chapter 2: Well-Formed XML

Chapter 3: XML Namespaces

Chapter 1

What is XML?

XML (Extensible Markup Language) is a buzzword you will see everywhere on the Internet, but it's also a rapidly maturing technology with powerful real-world applications, particularly for the management, display, and organization of data. Together with its many related technologies, which are covered in later chapters, XML is an essential technology for anyone working with data, whether publicly on the web or privately within your own organization. This chapter introduces you to some XML basics and begins to show you why learning about it is so important.

This chapter covers the following:

The two major categories of computer file types—binary files and text files—and the advantages and disadvantages of each

The history behind XML, including other markup languages such as SGML and HTML

How XML documents are structured as hierarchies of information

A brief introduction to some of the other technologies surrounding XML, which you will work with throughout the book

A quick look at some areas where XML is useful

While there are some short examples of XML in this chapter, you aren't expected to understand what's going on just yet. The idea is simply to introduce the important concepts behind the language so that throughout the book you can see not only how to use XML, but also why it works the way it does.

Of Data, Files, and Text

XML is a technology concerned with the description and structuring of data, so before you can really delve into the concepts behind XML, you need to understand how computers store and access data. For our purposes, computers understand two kinds of data files: binary files and text files.

Binary Files

A binary file, at its simplest, is just a stream of bits (1s and 0s). It's up to the application that created a binary file to understand what all of the bits mean. That's why binary files can only be read and produced by certain computer programs, which have been specifically written to understand them.

For instance, when a document is created with Microsoft Word, the program creates a binary file with an extension of “doc,” in its own proprietary format. The programmers who wrote Word decided to insert certain binary codes into the document to denote bold text, codes to denote page breaks, and other codes for all of the information that needs to go into a “doc” file. When you open a document in Word, it interprets those codes and displays the properly formatted text or prints it to the printer.

The codes inserted into the document are meta data, or information about information. Examples could be “this word should be in bold,” “that paragraph should be centered,” and so on. This meta data is really what differentiates one file type from another; the different types of files use different kinds of meta data. For example, a word processing document has different meta data than a spreadsheet document, because they are describing different things. Not so obviously, documents from different word processing applications, such as Microsoft Word and WordPerfect, also have different meta data, because the applications were written differently (see Figure 1-1).

Figure 1-1

You can't assume that a document created with one word processor will be readable by another, because the companies who write word processors all have their own proprietary formats for their data files. Word documents open in Microsoft Word, and WordPerfect documents open in WordPerfect.

Luckily, most word processors come with translators or import utilities, which can translate documents from other word processors into formats that can be understood natively. If I have Microsoft Word installed on my computer and someone gives me a WordPerfect document, I might be able to import it into Word so that I can read the document. Of course, many of us have seen the garbage that sometimes occurs as a result of this translation; sometimes applications are not as good as we'd like them to be at converting the information.

Binary file formats are advantageous because it is easy for computers to understand these binary codes—meaning that they can be processed much faster than nonbinary formats—and they are very efficient for storing this meta data. There is also a disadvantage, as you've seen, in that binary files are proprietary. You might not be able to open binary files created by one application in another application, or even in the same application running on another platform.

Text Files

Like binary files, text files are also streams of bits. However, in a text file these bits are grouped together in standardized ways, so that they always form numbers. These numbers are then further mapped to characters. For example, a text file might contain the following bits:

1100001

This group of bits would be translated as the number 97, which could then be further translated into the letter a.

This example makes a number of assumptions. A better description of how numbers are represented in text files is given in the “Encoding” section in Chapter 2.

Because of these standards, text files can be read by many applications, and can even be read by humans, using a simple text editor. If I create a text document, anyone in the world can read it (as long as they understand English, of course) in any text editor they wish. Some issues still exist, such as the fact that different operating systems treat line-ending characters differently, but it is much easier to share information when it's contained in a text file than when the information is in a binary format.

Figure 1-2 shows some of the applications on my machine that are capable of opening text files. Some of these programs only allow me to view the text, while others will let me edit it as well.

Figure 1-2

In its early days, the Internet was almost completely text-based, which enabled people to communicate with relative ease. This contributed to the explosive rate at which the Internet was adopted, and to the ubiquity of applications such as e-mail, the World Wide Web, newsgroups, and so on.

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!