如何可视化一组互连的 XML 对象?

发布于 2024-10-06 22:18:22 字数 394 浏览 5 评论 0原文

我有一些 XML 文档,经过非常简化,可以描述为:

<someobject id="mykey">
  <relatedobject id="hiskey"/>
  <relatedobject id="herkey"/>
</someobject>
<someobject ...

有什么简单的方法可以生成这样的图表,显示对象很好地放置在 2D 空间中,并且对象之间有线条?

我对 XSLT 和 Xpath 非常满意,但更喜欢不需要从头开始编写程序的解决方案。对 Saxon 进行一些命令行调用,然后生成图形就可以了。完全使用在线托管工具可以完成的任何事情都会获得奖励积分。现场(例如javascript)、交互式图表的额外奖励积分。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风启觞 2024-10-13 22:18:22

这是一个可以直接粘贴到 shell 的快速解决方案,使用 GraphViz 作为 菲利普建议。这利用 xmlstarlet 来避免从头开始编写 XSLT 样式表。

( echo "graph G {" 
  xmlstarlet sel -t -m "//someobject/relatedobject" \
    -v "concat(../@id, ' -- ', @id, '
')" input.xml 
   echo "}" ) | dotty -

示例输出:

alt text


编辑添加: 对于额外的奖励点,交互式 SVG仅使用在线工具的图表 此处。这利用了Dracula Graph LibraryW3C XSLT 服务。这需要创建一个 XSLT 样式表(直接改编自 Dracula 图形库的在线示例)。用于转换的输入文档可以在此处找到。

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:

alt text


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.

可是我不能没有你 2024-10-13 22:18:22

我建议使用 GraphViz:您使用 XSLT 创建一个文本文件,它描述了您想要的图表。请参阅此示例以获取快速概述。

我对它不太熟悉了,但我认为

graph G { 
  mykey -- hiskey
  mykey -- herkey
}

应该完成这项工作。

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.

傲娇萝莉攻 2024-10-13 22:18:22

这不是一个简单的问题。我很早以前写了一个程序来对XML文档进行聚类,但是显示的是网格而不是图形。不过,如果您要实现某些功能,您可能会对代码感兴趣。此外,您可以为文档添加关键字,关键字以及链接将用于对文档进行聚类,并且它们还将用于命名生成的聚类。当有大量文档时,网格显示可能比图表更好。

http://media4.obspm.fr/outils/clustering/doc_en.html

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文