Team LiB
Previous Section Next Section

Hack 59. Get Tools for XML Validation

Complement your XML content development processes with life-saving tools.

XML content is interpreted rather than compiled by Firefox. If XML is interpreted by a nonvalidating parser, only basic syntax errors are reported. This hack shows how to check your XML content more thoroughly.

There is no DTD or XML schema for either Mozilla's XUL or Mozilla's XBL dialects of XML.

6.3.1. Built-In XML-Checking Tools

Firefox's strict XML parser [Hack #58] checks all XML content for well-formedness. If the content is to be displayed as a document and it contains a simple syntax error, Firefox will display an error. This sample code has incorrectly nested tags:

<?xml version="1.0"?>

Figure 6-1 shows the error message that Firefox reports.

Figure 6-1. A standard XML error message

The problem is that Firefox reports these messages only if the XML content is destined for display. There's no handy feedback if the content is delivered into an existing document. Examples of content delivered into an existing, displayed document include RSS feeds, RDF datasources, XBL bindings, and SOAP messages. A simple test strategy is to manually load such XML directly into the browser using a URL or filename and see what happens.

Firefox's strict XML parser is not a validating parser. It doesn't check content against DTDs or schemas. This means that well-formed XML (or HTML) isn't checked for valid tags (entities). You have to use a separate tool for such a check. The forthcoming E4X support in JavaScript supports only the five standard entities defined by the base XML standard.

6.3.2. Web-Based Validation Tools

To validate your XML code, you can send it to a web site that provides a validation service. There are several styles of content submission. The following page-based service provides checking based on a tool called RXP. You can cut and paste your own URL into the displayed HTML form, and it will be checked for you:

This alternate service lets you upload a local file, use a URL, or paste an XML content fragment into its submission form:

6.3.3. Third-Party Validation Tools

You can pay a fortune for a GUI tool that does XML validation for you. Here are two products for Windows, both of which offer free trial versions:


This is a programmer-focused integrated development environment (IDE) tool with XML-validation features.

Schematron Validator (

This is a tool focused on data modeling and on editing and checking XML schema specifications and XML schema instances (XML documents).

Most software tool vendors with an XML focus include validation of some kind in their commercial offerings.

On Linux/Unix, quality GUI-based tools are less common. Of the GUI options available, the two main editors, Emacs and vi (vim is a modern vi offering) are both troublesome. Expect lots of web research and configuration time. Both editors support simple syntax-highlighting out of the box, but that is not validation.

Things are better at the command line, where libraries like libxml and expat have been built on to provide useful tools. I recommend these:


This is a set of XML validation tools with a syntax environment similar to cvs, except all commands are kicked off via the xml command. XMLStarlet is quick on the command line and can be easily integrated with makefiles, scripts, and other simple automations.

Raptor (

RDF overlays plain XML and XML schema content with an additional data model designed to represent arbitrary relationships between data. A simple validator is not always enough for RDF; Raptor requires compilation from source. A useful command-line tool called rapper analyzes RDF XML content from an RDF point of view.

    Team LiB
    Previous Section Next Section