XML to image – a quick way

Time and again there’s an xml file lying around whose structure you would like to have visualised – e.g. to print out and explain something to a coworker (or possibly crumple up and throw at a wall).

There are many different tools to achieve this objective, but some of them are costly while others are complicated to install and use for this seemingly small task.
Provided you are not looking for hi-res ‘bells and whistles’ visualisation, you may proceed as follows:

  1. If you already have a schema description, proceed to step 2. – If you have only an xml, obtain trang, a small xml schema converter
    sudo apt-get install trang
    and generate a schema file
    trang your.xml your.xsd
  2. Pick up a small java utility called xmlschema2graph* (includes standalone executable and ant task), unzip it and run
    java -jar XmlSchemaToGraph.jar -o output.dot  file:///path/to/your.xsd
    This creates a dot file useable by GraphViz.
  3. If necessary, install graphviz
    sudo apt-get install graphviz
    and create a printable representation of your schema
    dot -Tpng output.dot > your-schema.png
    (choose from dot’s many output options to suit your needs)

As an example: the schematics of /etc/cupshelpers/preferreddrivers.xml produced by following the steps described above.




*Its one and only release has been announced in July 2008, since then nothing has happened with (and to) the code base.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.