【问题标题】:How to process XML files using Graph::easy module in Perl如何在 Perl 中使用 Graph::easy 模块处理 XML 文件
【发布时间】:2011-11-22 15:07:27
【问题描述】:

我想使用 Perl 模块 Graph::easy 将 XML 文件转换为 graphML。我reeded Graph::module 然后我尝试了一些示例如何添加节点以及如何添加这样的边缘,然后我使用Graph::Easy 生成了graphML 文件。例如:

#!/usr/bin/perl
use warnings;
use strict;
use Graph::Easy;

my $graph = Graph::Easy->new();
$graph->add_edge( 'supplier', 'customer' );

open STDOUT,  '>',  'biji.graphml';
binmode STDOUT, ':encoding(UTF-8)';
print $graph->as_graphml();
close STDOUT;

运行此脚本后,它生成了一个 graphML 文件,我使用了一些工具在图形模型中表示它。但是如何使用 Graph::easy 处理这个 XML 文件并将其转换为 GraphML 文件呢?

<orderinfo>
 <servicename>scc</servicename>
  <Customer>bvr</Customer>
   <Suppliers>
     <Supplier Id="svr" />
   </Suppliers>
</orderinfo>

我需要在图中将供应商、客户和服务名称表示为节点和这些节点之间的边。我在一个文件中有很多这样的 XML 数据。谁能帮我解决这个问题?

【问题讨论】:

  • 如果我理解正确,您想稍后阅读带有 Graph::Easy 的 GraphML 文件。我怎么看,它没有 GraphML 解析器,它只有他自己的格式,VCG 和 GraphViz。见parsers
  • @XoR 不,我想使用 perl 将 xml 转换为 GraphML。

标签: perl graphml


【解决方案1】:

您的输入是 XML。您的输出是 XML 的一种方言。将一种 XML 转换为另一种的最好方法可能是使用 XSLT。根本不需要使用 Perl。

【讨论】:

  • 您能否提供一些使用 XSLT 将 xml 转换为 graphML 的示例。
【解决方案2】:

正如达沃格所说。您需要使用 XSLT。 XSLT 只是一个样式表。当你使用 perl 时,你不会离开它。 Perl 通过 XML::LibXSLT 等包提供对 XSLT 的支持。

您可以将这些包用于 XSLT。希望这会有所帮助。

请看 http://metacpan.org/pod/XML::LibXSLThttp://www.w3schools.com/xsl/

【讨论】:

  • 如果你不是我的,你能举一些例子来使用 XML::LibXSLT 将 xml 转换为 graphML。
  • 请分享一个示例 XML 和 graphML。我会为它写一个 XSLT 模板。
猜你喜欢
  • 2013-06-24
  • 1970-01-01
  • 1970-01-01
  • 2012-03-21
  • 2019-08-12
  • 1970-01-01
  • 1970-01-01
  • 2014-05-31
  • 1970-01-01
相关资源
最近更新 更多