Started as a question on Stack Overflow a couple of years ago but now gets used often enough to keep around.
- A way to generate xpaths from an XML file, I use xmlstarlet
- This xpath2dot awk script.
- A way to directly view (xdot), or convert to image a Graphviz dot file
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.py | dot -T png > xpath2dot_demo.png
xmlstarlet el -v RCV000077146.xml | xpath2dot.py | dot -T png > xpath2dot_demo.png
Include XML attributes:
xmlstarlet el -a RCV000077146.xml | sort -u | xpath2dot.awk | dot -T png > xpath2dot_demo.png
Include XML name references:
xmlstarlet el -v RCV000077146.xml | xpath2dot.awk | dot -T png > xpath2dot_demo.png