yEd GraphML

333 views
Skip to first unread message

Matt Shelton

unread,
Sep 28, 2010, 12:26:12 PM9/28/10
to networkx-discuss
Is anyone having problems reading GraphML files created by yEd?
Whenever I try to read a file created by yEd into a graph, NetworkX
throws the following exception:


File "myscript.py", line 51, in main
G = nx.read_graphml(argv[1])
File "/home/mjs/.local/lib/python2.6/site-packages/networkx/
readwrite/graphml.py", line 100, in read_graphml
glist=list(reader(fh))
File "/home/mjs/.local/lib/python2.6/site-packages/networkx/
readwrite/graphml.py", line 230, in __call__
(keys,defaults) = self.find_graphml_keys(self.xml)
File "/home/mjs/.local/lib/python2.6/site-packages/networkx/
readwrite/graphml.py", line 338, in find_graphml_keys
"type":self.python_type[k.get("attr.type")],
KeyError: None

This seems to be caused by yEd's yFiles extension. yEd-specific keys
do not have an "attr.type" attribute but rather "yfiles.type". For
example, the following was clipped out of a GraphML file created by
yEd:

<!--Created by yFiles for Java 2.7-->
<key for="graphml" id="d0" yfiles.type="resources"/>
<key attr.name="custom1" attr.type="string" for="node" id="d1">
<default/>
</key>
<key attr.name="custom2" attr.type="string" for="node" id="d2">
<default/>
</key>
<key attr.name="url" attr.type="string" for="node" id="d3"/>
<key attr.name="description" attr.type="string" for="node" id="d4"/>
<key for="node" id="d5" yfiles.type="nodegraphics"/>
<key attr.name="Description" attr.type="string" for="graph" id="d6">
<default/>
</key>
<key attr.name="url" attr.type="string" for="edge" id="d7"/>
<key attr.name="description" attr.type="string" for="edge" id="d8"/>
<key for="edge" id="d9" yfiles.type="edgegraphics"/>


Thoughts? I appreciate any responses in advance!

Matt

Aric Hagberg

unread,
Sep 28, 2010, 12:51:47 PM9/28/10
to networkx...@googlegroups.com
On Tue, Sep 28, 2010 at 10:26 AM, Matt Shelton
<matthew....@gmail.com> wrote:
> Is anyone having problems reading GraphML files created by yEd?
> Whenever I try to read a file created by yEd into a graph, NetworkX
> throws the following exception:
>
...

>    "type":self.python_type[k.get("attr.type")],
> KeyError: None
>
> This seems to be caused by yEd's yFiles extension.  yEd-specific keys
> do not have an "attr.type" attribute but rather "yfiles.type".  For
> example, the following was clipped out of a GraphML file created by
> yEd:
>
>  <!--Created by yFiles for Java 2.7-->
>  <key for="graphml" id="d0" yfiles.type="resources"/>
>  <key attr.name="custom1" attr.type="string" for="node" id="d1">
>    <default/>
>  </key>
>  <key attr.name="custom2" attr.type="string" for="node" id="d2">
>    <default/>
>  </key>
>  <key attr.name="url" attr.type="string" for="node" id="d3"/>
>  <key attr.name="description" attr.type="string" for="node" id="d4"/>
>  <key for="node" id="d5" yfiles.type="nodegraphics"/>
>  <key attr.name="Description" attr.type="string" for="graph" id="d6">
>    <default/>
>  </key>
>  <key attr.name="url" attr.type="string" for="edge" id="d7"/>
>  <key attr.name="description" attr.type="string" for="edge" id="d8"/>
>  <key for="edge" id="d9" yfiles.type="edgegraphics"/>

The NetworkX graphml reader and writer don't handle the yfiles
extension. But it doesn't look too hard to add that - or maybe it
should be a separate reader/writer?

Aric

Matt Shelton

unread,
Sep 28, 2010, 1:43:32 PM9/28/10
to networkx-discuss
Aric,

I feel like the yfiles extension does not provide much value to
networkx at the current moment. For example, yfiles provides a method
for encoding graphics into a graphml file. Although this is great
functionality, it's not necessarily something that would benefit
networkx as the current moment.

Matt

Aric Hagberg

unread,
Sep 28, 2010, 1:54:40 PM9/28/10
to networkx...@googlegroups.com
On Tue, Sep 28, 2010 at 11:43 AM, Matt Shelton
<matthew....@gmail.com> wrote:
> Aric,
>
> I feel like the yfiles extension does not provide much value to
> networkx at the current moment.  For example, yfiles provides a method
> for encoding graphics into a graphml file.  Although this is great
> functionality, it's not necessarily something that would benefit
> networkx as the current moment.

Is there a simple way to convert the GraphML with yfiles extensions to
standard GraphML?
Or maybe a simple modification in the NetworkX graphml reader we could
make so at least all of the "non yfiles" part of the GraphML can be
loaded?

Aric

Matt Shelton

unread,
Sep 28, 2010, 5:24:08 PM9/28/10
to networkx-discuss
I went ahead and wrote a script to strip out the yfiles extensions
from the graphml file. Using this tool, yEd graphml files import into
networkx beautifully. If anyone is interested, it can be downloaded
from the following site: http://github.com/mshelton/networkx/blob/master/scripts/stripYfiles.py

Matt

On Sep 28, 1:54 pm, Aric Hagberg <ahagb...@gmail.com> wrote:
> On Tue, Sep 28, 2010 at 11:43 AM, Matt Shelton
>

Aric Hagberg

unread,
Sep 29, 2010, 12:13:30 AM9/29/10
to networkx...@googlegroups.com
On Tue, Sep 28, 2010 at 3:24 PM, Matt Shelton
<matthew....@gmail.com> wrote:
> I went ahead and wrote a script to strip out the yfiles extensions
> from the graphml file.  Using this tool, yEd graphml files import into
> networkx beautifully.  If anyone is interested, it can be downloaded
> from the following site:  http://github.com/mshelton/networkx/blob/master/scripts/stripYfiles.py

That looks great. Thanks for doing that.

I opened a ticket to add the ability to read the yfiles extended graphml format:
https://networkx.lanl.gov/trac/ticket/442

Perhaps someone will pick that up and add the extra attributes.

Aric

Reply all
Reply to author
Forward
0 new messages