xmlplint command line tool


Xmlplint is command line tool for parsing/validating XML documents. Xmlplint means something like "xml parsing/parsifal lint" (http://en.wikipedia.org/wiki/Lint_programming_tool). Name resemblance with xmllint is obvious of course (xmlllint is very similar command line tool based on libxml framework). I chose the name just because I think it's easy to remember - not because I wanted people to mix up these tools. Xmllint/libxml offers quite impressive list of features but xmlplint offers some unique features like for instance streaming DTD validation (read: very fast and using memory sparingly) and partial DTD validation based on uris.


Xmlplint in action:



Features:


Installation

Xmlplint is included in the parsifal library distribution files in source form (see samples/xmlplint/INSTALL for installation instructions). Win32 binary files are also available. You can find them at the Download section. Xmlplint uses libiconv library so you must have one too (see also links for win_iconv). Get it for example here GNU.ORG libiconv. Also Win32 binary distribution doesn't include iconv.dll so you must download libiconv-1.9.1.bin.woe32.zip or similar.


Licence

Xmlplint uses libcurl library. Curl and libcurl are licensed under a MIT/X derivate license.
GNU libiconv uses LGPL licence
Parsifal XML Parser and xmlplint command line tool are Public Domain software


xmlplint usage
C:\xmlplint>xmlplint -?
Usage: xmlplint [options] <file/url>
Options:
  -V Validate document
  -a Sort attributes
  -v Show version info
  -x Skip external entities
  -M Load document into memory before processing
     (useful for benchmarking)
  -i Report ignorable whitespace
  -c Use catalogs file /etc/xml/catalog or files set by
     XML_CATALOG_FILES environment variable (semicolon separated)
  -W Treat validation errors as warnings
  -s Show error/warning status
  -d Load foreign DTD e.g. -d /home/mydtd.dtd
  -o Output to file
  -f Output format (default: roundtrip)
     1: SAX events
     2: canonical form (http://www.jclark.com/xml/canonxml.html)
     3: silent - errors only
  -e Force input encoding e.g. -e ISO-8859-1
  -X General entity settings
     1: Preserve general entities
     2: Treat undefined entities as errors
  -n Namespace handling (default: on)
     1: off
     2: report declarations
  -u Base uri
  -U Uri for DTD validation filter
  -t Benchmark processing time for specified iterations
     e.g. -t 1000
  -E Error reporting (default: verbose)
     1: simple (useful for editors)
     2: output displays UTF-8 (for column info)
  -F Set spesific parser flag(s) (see parsifal.h)
Example:
  xmlplint -V -f1 xmlfile.xml -o outfile.xml


Return values
0Success
1Document is not well-formed
2Document is well-formed but not valid
3Document not found or I/O error (triggered by libcurl etc.)
4Fatal error (cannot process document using specified settings or out of memory etc.)


catalog.xml example
<!DOCTYPE catalog
  PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN"
        "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">
        
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"
         prefer="public">
  <group xml:base="file://c:/xmlplint/DTD/">
  
    <public publicId="-//W3C//DTD XHTML 1.0 Transitional//EN" 
            uri="xhtml/xhtml1-transitional.dtd"/>
              
  </group>
</catalog>

This catalog example shows how to map publicIDs into local files:

  1. Download xhtml 1.0 dtds from w3c.org and extract them into c:\xmlplint\DTD\xhtml directory.
  2. Save this catalog.xml into xmlplint directory and set environment variable XML_CATALOG_FILES = c:\xmlplint\catalog.xml
  3. Now when your document uses publicId "-//W3C//DTD XHTML 1.0 Transitional//EN" xmlplint will fetch dtds from the local directory instead of loading them from the internet. You must of course use -c flag for xmlplint to enable xml catalogs support.

More info on xml catalogs can be found here and here



Integration with text editors


Here are settings for adding XML validation into UltraEdit-32 text editor. Tool configuration command line:

C:\xmlplint\xmlplint.exe -W -c -f 3 -E 1 -s -X 2 "%f"

Remove -c flag if you do not intent to use xml catalogs support (described above).

Choose appropriate settings for the tool "XML Validation":



Now choose preferred key combination/mapping for your tool and you can simply press that key combination to validate document that is currently active document in ultraedit. (If XML validation is at the top of the tool list in the tool configuration dialog the default key mapping is CTRL+SHIFT+0).


Copyright © 2002-2008 Toni Uusitalo.
Send mail, suggestions and bug reports to

Last modified: 04.10.2008 00:00