XML 建模工具

发布于 2024-12-02 09:25:19 字数 1539 浏览 3 评论 0原文

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

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

发布评论

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

评论(2

影子的影子 2024-12-09 09:25:19

我知道您正在寻求一个工具,并且您正在使用 UML 标记您的问题,但也许您会喜欢 Graph::Easy 模块使用 Perl,只是为了获得 XML 的第一个大视图。

这是示例 XML:

<test>
  <parent id="1"/>
  <parent id="2"/>
  <child id="11" mother="1" father="2"/>
  <child id="10" mother="1" father="2"/>
</test>

这是小脚本:

#!/usr/bin/perl -w
use 5.010;
use strict;
use warnings;

use Graph::Easy;
use IO::All;
use Path::Class;
use XML::LibXML;

my $graph   = Graph::Easy->new(timeout => 100);
my $parser  = XML::LibXML->new();
my $xmlFile = file('...') # Replace by your path.

my $dom = $parser->parse_file($xmlFile);
foreach my $childNode ($dom->findnodes('//child'))
{
    $graph->add_edge
    (
        $childNode->getAttribute('id'),
        $childNode->getAttribute('mother'),
        'has mother'
    );
    $graph->add_edge
    (
        $childNode->getAttribute('id'),
        $childNode->getAttribute('father'),
        'has father'
    );
}

$graph->as_svg > io("graph.svg");

和结果:

在此处输入图像描述

这只是一个非常简单的示例,但您可以轻松地进一步添加不同类型的线条、颜色等。例如:

在此处输入图像描述

I know you're asking for a tool, and you're tagging your question with UML, but perhaps you'll like the Graph::Easy module with Perl, just to get a first big view of your XML.

Here is the sample XML :

<test>
  <parent id="1"/>
  <parent id="2"/>
  <child id="11" mother="1" father="2"/>
  <child id="10" mother="1" father="2"/>
</test>

Here is the little script :

#!/usr/bin/perl -w
use 5.010;
use strict;
use warnings;

use Graph::Easy;
use IO::All;
use Path::Class;
use XML::LibXML;

my $graph   = Graph::Easy->new(timeout => 100);
my $parser  = XML::LibXML->new();
my $xmlFile = file('...') # Replace by your path.

my $dom = $parser->parse_file($xmlFile);
foreach my $childNode ($dom->findnodes('//child'))
{
    $graph->add_edge
    (
        $childNode->getAttribute('id'),
        $childNode->getAttribute('mother'),
        'has mother'
    );
    $graph->add_edge
    (
        $childNode->getAttribute('id'),
        $childNode->getAttribute('father'),
        'has father'
    );
}

$graph->as_svg > io("graph.svg");

and the result :

enter image description here

That's just a very simple example, but you can easily go further and add different types of lines, colors, etc. By example :

enter image description here

请爱~陌生人 2024-12-09 09:25:19

也许您使用了错误的工具? XML 最适合识别以自上而下的树结构存储的数据。您所描述的结构具有更复杂的关系(父级在某些情况下可能是顶级元素,在其他情况下是低级元素)...关系数据库(例如,基于 SQL)更擅长描述某些关系。

Perhaps you're using the wrong tool? XML is best for identifying data stored as top-down tree structures. The structure your describing has more complex relationships (parents may in some instances be the top level element, in others the low level element)... something that a relational database (for example, SQL based) would be better at describing.

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