in reply to which is the best way to convert xml to GraphML using perl.
The Graph::Easy distribution will do the job. To get a GraphML text, use Graph::Easy::As_graphml. Here's the documentation's example. I saved the output to file.
Outputs:#!/usr/bin/perl -slw use strict; use Graph::Easy; my $graph = Graph::Easy->new(); $graph->add_edge( 'Bonn', 'Berlin' ); open STDOUT, '>', 'graph.graphml'; binmode STDOUT, ':encoding(UTF-8)'; print $graph->as_graphml(); close STDOUT;
Use Graph::Easy::Parser to create a Graph::Easy object that you can convert to a graph. I used the as_ascii method.<?xml version="1.0" encoding="UTF-8"?> <graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd"> <!-- Created by Graph::Easy v0.70 at Thu Nov 17 03:13:06 2011 --> <graph id="G" edgedefault="directed"> <node id="Berlin"> </node> <node id="Bonn"> </node> <edge source="Bonn" target="Berlin"> </edge> </graph> </graphml>
Give it try. Good luck.#!/usr/bin/perl -slw use strict; use Graph::Easy; use Graph::Easy::Parser; my $parser = Graph::Easy::Parser->new(); print $parser->from_text('[Bonn]->[Berlin]')->as_ascii();
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: which is the best way to convert xml to GraphML using perl.
by veerubiji (Sexton) on Nov 21, 2011 at 12:23 UTC | |
Re^2: which is the best way to convert xml to GraphML using perl.
by veerubiji (Sexton) on Nov 22, 2011 at 13:40 UTC | |
by Khen1950fx (Canon) on Nov 23, 2011 at 12:47 UTC |
In Section
Seekers of Perl Wisdom