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.
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"?> <foo> <bar> </foo> </bar>
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.
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:
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: