Reputation: 125995
I have some XML documents which, grossly simplified, can be described as:
<someobject id="mykey">
<relatedobject id="hiskey"/>
<relatedobject id="herkey"/>
</someobject>
<someobject ...
What would be a simple way to produce a diagram of this, showing the objects placed nicely in 2D space, with lines between them?
I'm very comfortable with XSLT and Xpath, but would prefer a solution that doesn't require writing a program from scratch. Making a few command line calls to Saxon then a graph generating prog would be ok. Bonus points for anything that can be done totally using online hosted tools. Extra bonus points for a live (eg javascript), interactive diagram.
Upvotes: 3
Views: 1636
Reputation: 10188
Here's a quick solution that can can be directly pasted to a shell, using GraphViz as suggested by Philipp. This makes use of xmlstarlet to avoid having to write an XSLT stylesheet from scratch.
( echo "graph G {"
xmlstarlet sel -t -m "//someobject/relatedobject" \
-v "concat(../@id, ' -- ', @id, '
')" input.xml
echo "}" ) | dotty -
Sample output:
Edited to add: And for the extra bonus points, an interactive SVG diagram using only online tools here. This makes use of Dracula Graph Library and the W3C XSLT Service. This required creating an XSLT stylesheet (directly adapted from the online examples for Dracula Graph Library). The input document used for the transformation can be found here.
Upvotes: 3
Reputation: 3220
This is not a simple problem. I wrote a program a long time ago to cluster XML documents, but the display is a grid instead of a graph. Still, you might be interested in the code if you're going to implement something. Additionally, you can attribute keywords to your documents, and the keywords will be used as well as the links to cluster the documents, and they will also be used to name the resulting clusters. The grid display is probably better than a graph when there are lots of documents.
http://media4.obspm.fr/outils/clustering/doc_en.html
Upvotes: 0
Reputation: 11814
I'd suggest to use GraphViz: You create a text file using XSLT which describes the graph you would like. See this example for a quick overview.
I'm not too familiar with it anymore, but I think
graph G {
mykey -- hiskey
mykey -- herkey
}
should do the job.
Upvotes: 2