Ray. E. (2001) Learning XML, O'Reilly, Sebastapol.

Erik Ray's Learning XML is quite simply the best general introduction to XML that I have read to date. Indeed, I am so impressed that I shall be recommending its free distribution to delegates on our XML training courses.

0'Reilly deserve congratulation for resisting the temptation, to which most technical publishers have succumbed, of rushing out an XML `instant book'. With this volume at least, they have returned to the tradition which established their reputation i.e. a tradition of considered and thoughtful texts which have become definitive works by concentrating on the clear and orderly elaboration of fundamentals.

Learning XML doesn't intend to teach you advanced XML programming, nor does it have to. Its purpose is to give a "bird's eye view of the XML landscape", i.e. to provide a good enough overview of XML for you to learn its programming yourself. It significantly exceeds this modest ambition.

Whilst it is decidedly not an instruction manual, Learning XML does explain how to use all of the basic XML tools and techniques. Moreover, it is hard to imagine how any moderately intelligent reader of it could fail to understand and apply the core concepts which underlie XML production, processing and management.

Experienced and able programmers do not need this book - most can go straight to the Worldwide Web Consortium's XML Specification pages to get themselves started - but they would, nevertheless, be well-advised to cast a brief glance in its direction. XML may be easy to implement, but bad XML is even easier. A good conceptual grounding in the language could save a lot of time and grief being wasted on ill-considered design and architecture.

Erik Ray's greatest achievement in writing this XML book has been to ruthlessly exclude the merely relevant from his discussion. With one or two notable exceptions, most pages in Learning XML are devoted to simply explaining and illustrating core XML concepts. Details which needlessly consume the reader's time, overload their capacity to digest and obscure the truly critical issues, are typically avoided. When details are provided, they are invariably well organised, both sequentially and hierarchically. Unlike so many of the genre, one rarely feels that the subsequent topic appears simply because it was the next thing that the author thought of.

Knowing the quality of Ray's selection should warn readers against the temptation to skip chapters 1 and 2, i.e. the introductory overview and review of core XML concepts. Those familiar with the historical development of HTML out of successive markup standards (SGML and its predecessors, GCA, GML, etc.) will, for example, be pleased to note that the second chapter spends only the necessary minimum of time on the story, i.e. just enough to explain the rationale behind current XML specifications and tools.

Chapter 1 tells us almost everything we need to know about the XML's design goals in 5 sub-headings, i.e. that:

The descriptive section entitled "What is XML?" informs the beginner in unambiguous terms that:

Kay's single page summary of the relationship between XML and its satellite technologies will be particularly welcomed by first-timers seeking to map the XML landscape. Buzzwords and phrases put in their proper place include: `core syntax', `XML specification', XLinks, XHTML, MathML, DTD, XML Schema, XPath, XPointer, XQL, XSL, XSLT, XSL-FO, CSS, DOM, `the XML Information Set', the `XML Fragment Interchange' and SAX.

Finally, Chapter One concludes with an incomparably clear overview of the available tools and techniques for creating, viewing, testing and transforming XML documents. Instead of listing every conceivable XML editor, the author simply gives us short descriptions of the most mature and useful tools: vim, emacs, Arbortext Adept, Framemaker+SGML, XMetal and Conglomerate. No introductory chapter I have read has so clearly set out the functional differences between the various stylesheet languages and perspectives in XML, i.e. CSS, XSL, DSSL, FOSI and proprietary languages like XPP. The same goes for Ray's coverage of the validating parsers used to check XML and the transformation engines used to translate it.

Chapter Two's discussion of markup and core concepts fills out some ideas introduced in chapter one, whilst introducing some completely new ones. Each of its subsections have consumed entire chapters in other books, e.g.

Putting these topics side by side as brief synopses provides a conceptual overview, conveying far more of their meaning than detailed, but isolated, accounts of their individual mechanics. Books which provide the latter are largely redundant, since the W3 Consortium's official specifications usually do the job more completely and less ambiguously.

Above all, this chapter establishes the fact that Ray is not afraid to give advice — a breath of fresh air in a field where inexperience and the absence of critical distance so often take cover behind the spurious masque of choice and consumer sovereignty.

Chapter Three deals with XML linking, starting with a clear account of what a link actually is. Less reflective web designers may be surprised to discover not only range of XML linking techniques, but also the issues they have taken for granted in using simple HTML links.

Ray shows us how resources can be specified by naming formal public identifiers rather than the locations (URLs) we currently use in HTML. The use of ID and IDREF XML element attributes to create internal links within XML documents is simply outlined, as is the use of Xpointer extensions to URLs for reaching deep inside an XML document, using both absolute and relative paths to target information.

A significant proportion of Chapter Three is devoted to a tantalising introduction of XLinks; the sophisticated form of linking which XML permits, but which few have widely explored. Unlike HTML hypertext links which can only be created with dedicated link elements like the <a> tag, any element of an XML document can be made into an XLink. Equally importantly, the target of an XLink can be a point or range of points anywhere within a document, i.e. there is no need to provide dedicated anchor tags to point at. Whilst much of the potential for XLinks is currently unexploited and to some degree unexploitable, Ray gives useful illustrative examples from XML compliant XHTML.

Perhaps the most useful components of Chapter Three are the admirably simple, and graphically illustrated, examples of how relative paths within a document can be traversed by links, using XPath functions. Whilst the basic idea of traversing XML documents is no more difficult than anything else in the specification, the graphic illustrations dispel any ambiguity that the newcomer might discern in the textual description.

The one obvious, and unfortunate, omission from this consideration of XML linking is any real discussion about why one might want to undertake the various traversals which it demonstrates. A few concrete, real-world examples of tasks you might want to pursue would not have gone amiss.

Chapter Four deals with presentation issues and is largely a discussion of the various stylesheet languages and techniques which can be used to render XML on a range of devices from PC monitors to braille readers.

The chapter begins by recounting the sorry tale of HTML, its presentational extensions and the bad habits they engendered. It tantalisingly eschews all discussion of XSL-FO formatting objects on the grounds that they are not yet finished or even defined.

The section on Cascading Style Sheets (CSS) details how they enable the separation of some style from content. It is particularly good at conveying the notions of cascading, inheritance and rule conflict in applying style to marked up content. Of these, the sections dealing with how to resolve conflicts between different formatting rules are perhaps the most enlightening.

Rules match styles to content. Ray provides us with the essential minima for selecting elements and attributes in context, e.g. accounting for their ancestry, position, etc. The section ends with a brief 4-point checklist for conflict resolution:

  1. IDs are the most specific selector possible.
  2. More attribute selectors and pseudo-classes are stronger than fewer.
  3. Precise genealogical descriptions trump less precise chains.
  4. All other things being equal, rules appearing later in a stylesheet trump earlier ones.

Property declarations are applied to content which matches the winning selection rules. They specify properties like inheritance or units of measurement to block, inline and invisible display types.

Sadly and, in my view, mistakenly, Ray omits tables and lists from his discussion on the grounds that they are "too complex to be discussed here".

Notwithstanding my general admiration of his selectivity, I believe Ray has missed an important opportunity here, i.e. the opportunity to explain in simple terms important parts of the CSS specification which neither the definitive recommendation, nor published tutorials have done at all well. Given the limited space available, he might have used some of the pages devoted to vague overviews of internationalisation and XML programming for this purpose.

Chapter Five provides a general introduction to XML document models and document modelling concepts — something conspicuously lacking in several books which dive straight into the "how to" of document modelling without ever addressing the practical question of "why bother?". Kay does the job well, with simple and concrete definitions, pointing out for example that the document type of an XML application "explicitly lays out the grammar and vocabulary of a single markup language".

The vast bulk of the chapter is given over to DTD syntax, in lots of detail; arguably more than is strictly necessary to cover its main themes, i.e. element declarations, attribute declarations (including non-parsed data) and entity declarations.

Ray provides an extremely well thought out section of tips for designing and customising DTDs, putting the emphasis on simplicity, modularity and manageability. Good annotated examples are provided from a very simple personal chequebook accounting DTD and from the much larger bare-bones simplification of the DocBook mark-up language for technical documentation.

On the other hand, the over-brief taster which Ray provides of XML schemas in general and the official XML Schema Specification in particular, feels like s step too far in the direction of austere selection. Having identified some serious and practical limitations to DTD-based document modelling (old, inflexible, and inexpressive syntax, difficult to read and understand, inability to specify paths for elements and attributes, etc.) and having pointed up the benefits of XML schema syntax (it's well-formed XML, can be written with XML editors, provides control over data types and patterns and hence data entry, etc.) I think Ray owes more than a mere whiff of XML schema. At best he is an insufferable tease, at worst he is depriving his readership of the wherewithal to address what promises to be the future of XML document modelling — not least because XML Schema is easier to explain and implement. Tellingly, Ray concludes the chapter by saying that DTDs will be around for a long time yet, without making much attempt to explain or justify the assertion.

Chapter Six deals with transformation and repurposing documents (i.e. the real meat of XML processing). It is a monster of a chapter, covering over 70 pages and, frankly far too much information to deal with in one glob. Indeed, one suspects that Ray realised this at some point and began to substitute tables of functions for proper explanation, in the vain hope that he could cover the ground in less pages towards the end of the chapter.

Such is the speed of progression through the latter part of this chapter that, at times, it becomes more of a reference text than a tutorial.

I understand the desire to hold all the information together under the singular title of "Transformation", but I suspect that Ray would have been better advised to split the book into "Parts" with several transformation chapters in one of those parts, covering:

  1. Basic transformation concepts (nodes, node types, expressing structure with templates, stylesheets with XML syntax, applying XSLT stylesheets).
  2. Navigating and selecting nodes with location paths and pattern matching (including how to resolve conflicting match patterns).
  3. Extracting information from matching nodes with XPath expressions (which is dealt with far too briefly here).
  4. Creating and manipulating structures with templates (including selecting node sets, looping through node sets, creating/generating node sets in the output, sorting node sets).
  5. Using named templates like sub-routines.
  6. Passing parameters and constraints to template rules.
  7. Using "modes" to modify rules.
  8. Handling text and whitespace
  9. Combining style sheets.

Cramming so much detail into points 1-4 left little space for points 5-8. It is ironic, that whilst Ray described these as appropriate for XSLT power users, his brevity in discussing them actually made them easier to comprehend and apply.

Hardcore programmers will consider Chapter Seven a complete waste of time, since it is largely devoted to explaining stuff they already know about character encoding, i.e. its concepts, practice, well-known character sets and the reasons for using Unicode as XML's default encoding scheme.

For that audience the intellectually undemanding, but nonetheless novel, information is delivered in four pages which might have been tacked on to any one of several other chapters. These are:

For non-programmers, novices and Americans this chapter's brief dip into the multi-cultural, multi-lingual world of XML may be more interesting, but still probably less important than some of the material excluded from previous chapters.

Calling Chapter Eight "Programming for XML" is faintly misleading since it does little more than raise some issues. As the author admits, he intends to "keep the discussion short and general", allowing the reader "to choose the best way to go".

Even this modest ambition, Ray deserves congratulation for fully explaining one essential topic which many much longer books have failed to even address, i.e. the components and operation of an XML processor. While others have been content to follow the XML specification in treating the processor as a "black box", Ray shows us how a typical XML processor comprises four components, each with its own function:

  1. The XML Parser, which translates XML mark-up and data into a stream of tokens.
  2. The XML Event Switcher, which sorts the tokens according to function and routes event tokens to an event-handler, or call-back procedure.
  3. Call-back procedures, responding to events in the event handler add nodes to an internal tree-like representation of the document until there are no more events.
  4. The Tree Processor then processes this tree instead of the event stream (the tree being either a simple hierarchy of nodes or a complete "object model" in which every node is represented as a programmable object.

The chapter's brief introductions to event-driven XML processing with the Simple API for XML (SAX) and to tree-based processing via the Document Object Model are perfunctory, to say the least. Although clearly explained, they will find their most productive use as "bluffers' guides", since their contents are reproduced on virtually every XML text or site I have see, and are properly explained in many.

The well-commented Perl code for handling both sorts of programming may be useful as "quick-starts" who know that language already, but are of limited value for others.


This is a book which starts much better than it finishes, whether the tail-off in detail or coherence towards the end is down to approaching deadlines, page limits, or the product of design is hard to tell.

Recognising this deficiency should not, however, deter the XML novice from picking it up. For, with all my criticisms, I still consider it the best conceptual introduction to XML that I have read — and I promise you, I have read a sackful of them.

At least until two thirds of the way through the book, Ray retains admirable selectivity and applies a precise focus on the stuff that really matters. Buy it for that.