graphstream / gs-core

Graphstream core
http://graphstream-project.org/
Other
398 stars 109 forks source link

Error parsing graphml file #363

Open robinschmid opened 2 years ago

robinschmid commented 2 years ago

We are using graphstream 2.0 from maven central in a Java 16 project.

Somehow I cannot read a simple graphml file with node attributes. The __characters method within the FileSourceXML#Parser always returns "[Stax Event #4]" as a value although the original double value is 0.0. I tracked it down to this line:

https://github.com/graphstream/gs-core/blob/18d5f00ca9984f9279c38bb70177fae5ab2a4319/src/org/graphstream/stream/file/FileSourceXML.java#L463

org.codehaus.stax2.ri.evt.CharacterEventImpl.asCharacters() seems to be the wrong method to get the data.

it should be e.getData() or e.mContent

robinschmid commented 2 years ago

Here is the example graphml (simplified):

<?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">
<key attr.name="EdgeType" attr.type="double" for="edge" id="d2"/>
<key attr.name="G4" attr.type="double" for="node" id="d1"/>
<graph id="G" edgedefault="undirected">
<node id="1">
  <data key="d1">0.0</data>
</node>
<node id="2">
  <data key="d1">2</data>
</node>
<edge id="e1" source="1" target="2">
  <data key="d2">1.0</data>
</edge>
</graph>
</graphml>

And the code for the import:

      FileSource fs = new FileSourceGraphML();
      fs.addSink(graph);
      fs.readAll(file.getAbsolutePath());