Re: which is the best way to convert xml to GraphML using perl.
by Khen1950fx (Canon) on Nov 17, 2011 at 12:08 UTC
|
#!/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;
Outputs:
<?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>
Use Graph::Easy::Parser to create a Graph::Easy object that you
can convert to a graph. I used the as_ascii method.
#!/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();
Give it try. Good luck.
| [reply] [d/l] [select] |
|
|
| [reply] |
|
|
example.xml
<?xml version="1.0" encoding="UTF-8" ?>
<specification xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<orderinfo>
<servicename>ssc</servicename>
<Customer>dvr</Customer>
<Suppliers>
<Supplier Id="L7a" />
</Suppliers>
</orderinfo>
</specification>
I need to disply like servicename , customer, supplier as three nodes and edges from supplier to service name and service name to customer.I have large xml file like with same type of data. can you help or provide some examples.
| [reply] [d/l] |
|
|
It's confusing at first, but once you actually try to do something with it, it works. Here's a simple script to get
you started. I just added a couple of edges, but I think that
you'll be able to add some nodes and attributes after awhile.
#!/usr/bin/perl
use strict;
use warnings;
use Graph::Easy qw/as_graphml as_graphml_file/;
my $graph = Graph::Easy->new();
my $graphml_file = $graph->as_graphml_file();
$graphml_file =~ s/\n.*<!--.*-->\n//;
my $graphml = $graph->as_graphml();
$graph->add_edge('orderinfo', 'servicename');
binmode STDOUT, ':encoding(UTF-8)';
print $graphml = $graph->as_graphml();
| [reply] [d/l] |
Re: which is the best way to convert xml to GraphML using perl.
by marto (Cardinal) on Nov 17, 2011 at 09:30 UTC
|
"But yEd graph editor is not support to xml, so I need to convert XML into GraphML file then I can use that GraphML format in yEd graph editor."
Firstly yEd states:
"yEd can import data in various formats to generate diagrams out of it. Import formats include the Microsoft Excel .xls format for spreadsheet data, the Gedcom format for genealogical data, and also arbitrary XML-based file formats, which are transformed by means of XSLT stylesheets. Predefined XSLT stylesheets provided by yEd can process the Apache Ant build script format used to define dependency information in software build processes and the OWL file format for the description of ontologies. Other XML-based data is processed in a generic way."
I suggest you confirm this, and test to see if your XML can be used as an input. Had you super searched you'd have found nodes where people claim to have used yEd with XML, I dare say a google search would also be helpful.
Secondly, since you came to the conclusing that yEd didn't support xml, why did you choose it as the product to use in the first place?
| [reply] |
|
|
sorry, I posted little bit confusing, Actually my problem is I have the input format as xml and I need to represent in model graph so I chosen yEd graph editor, It import xml data and displaying tree structured graph, I need to display in some other way so I need to convert it into GraphML. GraphML is the native format for yEd so I am trying like that.Can you suggest which perl module is good doing this.
| [reply] |
|
|
So your strategy, is to ignore all questions put to you, and simply repeat your original question, in a slightly more verbose way?
Sure, the answer is, any one of these (and more): XML::Twig, XML::LibXML, XML::Rules, xsh, Graph::Easy::As_graphml
There are tons of docs, tons of examples included, lots of examples at perlmonks...
| [reply] |
|
|
| [reply] |
Re: which is the best way to convert xml to GraphML using perl.
by Anonymous Monk on Nov 17, 2011 at 09:16 UTC
|
The best way, is to not do it at all
Find a tool that does it, it must exist already
| [reply] |
|
|
i totally agree find a tool that does graphical representation like an xml editor, i think liquid xml editor can do it, http://www.liquid-technologies.com/xml-editor.aspx.
| [reply] |
Re: which is the best way to convert xml to GraphML using perl.
by mrguy123 (Hermit) on Nov 17, 2011 at 11:36 UTC
|
Can you give us a small example of how your XML looks, and how you want the GraphML format to look?
It will give us a better understanding on what exactly you want to do | [reply] |
|
|
| [reply] |