1

I want to convert an XML file to graphML using the Perl module Graph::easy. I reeded Graph::module then I tried some examples how to add node and how to add edge like that and I generated graphML file using Graph::Easy. For example:

#!/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;

After running this script it generated a graphML file and I used some tool to represent it in graph model. But how do I process this XML file using Graph::easy and convert it into GraphML file?

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

I need to represent in the graph supplier and customer and service name as nodes and edges between these nodes. I have lot of XML data like this in a file. Can any one help me with this problem?

Kris
  • 14,426
  • 7
  • 55
  • 65
biji
  • 59
  • 7
  • If I understood you correctly, you want to read afterwards GraphML file with Graph::Easy. How I see it, it doesn't have GraphML parsers, it only have his own format, VCG & GraphViz. See [parsers](http://search.cpan.org/~shlomif/Graph-Easy-0.70/) – XoR Nov 22 '11 at 15:37
  • @XoR No i want to convert xml to GraphML using perl. – biji Nov 22 '11 at 18:02

2 Answers2

0

Your input is XML. Your output is a dialect of XML. The best way to convert one kind of XML to another is probably to use XSLT. No need to use Perl at all.

Dave Cross
  • 68,119
  • 3
  • 51
  • 97
0

As davorg said. You need to use XSLT. XSLT is just an style sheet. You are not going away from perl when you will use it. Perl provides support of XSLT with packages like XML::LibXSLT and many more.

You can use these packages for XSLT. Hope this will help.

Please see http://metacpan.org/pod/XML::LibXSLT and http://www.w3schools.com/xsl/

szabgab
  • 6,202
  • 11
  • 50
  • 64
rpg
  • 1,632
  • 2
  • 18
  • 34
  • If you don't mine can you give some example to convert xml to graphML using XML::LibXSLT. – biji Nov 23 '11 at 08:07
  • please share a sample XML and graphML. I will write an XSLT template for it. – rpg Dec 27 '11 at 05:56