/xpath2dot

Visualize XML document structure

Primary LanguageAwk

XPath to GraphViz dot

Started as a question on Stack Overflow a couple of years ago but now gets used often enough to keep around.

Requirements:

Simple Usage:

Starting with a XML file which might change or go away from ftp://ftp.ncbi.nlm.nih.gov/pub/clinvar/xml/sample_xml/RCV000077146.xml

wget -q ftp://ftp.ncbi.nlm.nih.gov/pub/clinvar/xml/sample_xml/RCV000077146.xml

Which I will keep a snapshot of here.

xmlstarlet el -u RCV000077146.xml | xpath2dot.awk | dot -T png > xpath2dot_demo.png

Result:

Example xpath2dot output

More Usage:

Include XML attributes and change orientation to vertical

xmlstarlet el -a RCV000077146.xml | sort -u | \
 xpath2dot.awk -v ORIENT="UD" | dot -T png > xpath2dot_demo_att.png

Result:

Example xpath2dot with attributes output