I’m having trouble reading a GraphML file using the Boost Graph Library. The file is created without issues, but reading it back throws a parse error. Here’s a summary of what I’m doing:
-
I Create my example of graph and I save it using
write_graphml
. This graph only has an unique Vertex Property and no Edge properties. The code used to do so is:... variables ... typedef boost::property<boost::vertex_name_t, std::string> Node_name; typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, Node_name> Graph; typedef boost::graph_traits<Graph>::vertex_descriptor Vertex; typedef std::unordered_map<std::string, Vertex> VertexMap; Graph g; VertexMap vertex_map; ... build the graph ... std::string name = "../tmp/" + analyzed_file + ".graphml"; std::ofstream graph_ML(name); boost::dynamic_properties dp; dp.property("name", boost::get(boost::vertex_name, g)); boost::write_graphml(graph_ML, g, dp);
This code works perfectly. My file is properly saved in the desired directory.
-
However, when I try to read it with the following code:
std::string graph_ml_file_name = "../tmp/" + analyzed_file + ".graphml"; std::ifstream graphml_file(graph_ml_file_name); if(!graphml_file) { std::cerr << "Error opening the file" << std::endl; return -1; } boost::dynamic_properties dp; dp.property("name", boost::get(boost::vertex_name, g)); try { boost::read_graphml(graphml_file,g,dp); } catch(const std::exception& e) { std::cerr << "Error opening the graphml file" << e.what() << std::endl; return -1; }
I receive the error: Error opening the graphml file: parse error: unrecognized type “
I’ve looked through the documentation and couldn’t find specifics about handling this error. Has anyone faced this issue or can suggest what might be going wrong?
I have been researching similar errors online as well as reading the official Boost Graph documentation, but I have not found a solution.
StressedStudent is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.