Test XML Documents from the Command Line
A number of free, easy-to-use XML processors are available for use on the command line. This hack shows where to get four such tools and how to use them.
You can check XML documents for well-formedness and validity using tools on the command line or shell prompt. This hack discusses four tools: Richard Tobin’s RXP, Elcel’s XML Validator (xmlvalid), Daniel Veillard’s xmllint, and xmlwf (an application based on James Clark’s Expat C library).
RXP
You’ve already seen the online version of RXP [Hack #8] . This hack shows you how to use the command-line version, available free at http://www.cogsci.ed.ac.uk/~richard/rxp.html. For Windows and other platforms, you can download the C source and compile it yourself (ftp://ftp.cogsci.ed.ac.uk/pub/richard/rxp.tar.gz) or, if you are on Windows, you can simply download the executable rxp.exe (ftp://ftp.cogsci.ed.ac.uk/pub/richard/rxp.exe).
Once you’ve downloaded RXP and placed it in your path, you can check XML documents for well-formedness at a command prompt with this:
rxp time.xml
Upon success, this command will produce the output shown in Example 1-12.
Example 1-12. Output of RXP with time.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- a time instant -->
<time timezone="PST">
<hour>11</hour>
<minute>59</minute>
<second>59</second>
<meridiem>p.m.</meridiem>
<atomic signal="true"/>
</time>You can also check a document for validity by using the
-V option, provided it has an accompanying DTD (as
valid.xml ...