I am trying to read graph related (custom) properties from a .graphml file created with yEd using the Boost Graph library. Reading vertex and edge (dynamic_)properties works but my graph properties are always empty. I've also came across how to read graph-domain attributes with boost::read_graphml? but that solution just produces empty strings (it's in the code below). Apart from that, I was not able to find much information about the problem.
Here's the shortened code (complete working example test.cpp
here):
struct VertexProperties { string url, description; };
struct EdgeProperties { string url, description; };
struct GraphProperties { string title; };
// ...
typedef adjacency_list<vecS, vecS, directedS, VertexProperties, EdgeProperties, GraphProperties> DirectedGraph;
typedef dynamic_properties Properties;
DirectedGraph graph(0);
Properties props(ignore_other_properties);
props.property("url", get(&VertexProperties::url, graph));
props.property("description", get(&VertexProperties::description, graph));
props.property("url", get(&EdgeProperties::url, graph));
props.property("description", get(&EdgeProperties::description, graph));
map<string, string> attribute_name2name;
associative_property_map<map<string, string>> graphname_map(attribute_name2name);
props.property("title", graphname_map);
// ...
read_graphml(validated, graph, props);
graph[graph_bundle].title = get(graphname_map, "title");
cout << "\"" << graph[graph_bundle].title << "\"" << endl;
You can compile the full code using g++ test.cpp --std=c++11 -o test -lboost_graph
. Running it with ./test simple_graph.graphml
produces just "" instead of "foobar" which is the expected output since the graph has the
<data key="d1"><![CDATA[foobar]]></data>
tag which is defined as
<key attr.name="title" attr.type="string" for="graph" id="d1">
<default/>
</key>
I've uploaded an simple_graph.graphml example file (not enough rep. to post img / more details).
Minor follow-up question: is it possible to load the graph w/o 'fixing' the yEd-exported file (cf. code)? The parser always complains about lines like this (not sure if it's even permitted in the GraphML standard allowed in the standard: "This group consists of the two optional attributes - attr.name (gives the name for the data function) - attr.type ((declares the range of values for the data function)."):
<key for="port" id="d2" yfiles.type="portgraphics"/>
with this error:
parse error: unrecognized type "" for key
Any help/ideas are highly appreciated. Thank you very much!