bool GraphMLParser::readData( GraphAttributes &GA, const node &v, const XmlTagObject &nodeData) { XmlAttributeObject *keyId; nodeData.findXmlAttributeObjectByName("key", keyId); if(keyId == NULL) { cerr << "ERROR: Node data does not have a key.\n"; return false; } const long attrs = GA.attributes(); std::stringstream value(nodeData.getValue()); switch (graphml::toAttribute(m_attrName[keyId->getValue()])) { case graphml::a_nodeLabel: if(attrs & GraphAttributes::nodeLabel) { value >> GA.label(v); } break; case graphml::a_x: if(attrs & GraphAttributes::nodeGraphics) { value >> GA.x(v); }
bool Parser::readNodes(Graph &G, GraphAttributes *GA) { List<XmlTagObject *> nodeTags; m_nodesTag->findSonXmlTagObjectByName("node", nodeTags); for(XmlTagObject *obj : nodeTags) { const XmlTagObject &nodeTag = *obj; XmlAttributeObject *idAttr; nodeTag.findXmlAttributeObjectByName("id", idAttr); if(!idAttr) { OGDF_ERROR("node is missing an attribute " << "(line " << nodeTag.getLine() << ")."); return false; } const node v = G.newNode(); m_nodeId[idAttr->getValue()] = v; if(GA) { readAttributes(*GA, v, nodeTag); } } return true; }
bool Parser::readCluster( Graph &G, ClusterGraph &C, ClusterGraphAttributes *CA, cluster rootCluster, const XmlTagObject &rootTag) { List<XmlTagObject *> nodeTags; rootTag.findSonXmlTagObjectByName("node", nodeTags); for(XmlTagObject *obj : nodeTags) { const XmlTagObject &nodeTag = *obj; XmlAttributeObject *idAttr; nodeTag.findXmlAttributeObjectByName("id", idAttr); if(!idAttr) { OGDF_ERROR("node is missing an attribute " << "(line " << nodeTag.getLine() << ")."); } // Node is a cluster iff it contains other nodes. XmlTagObject *nodesTag; nodeTag.findSonXmlTagObjectByName("nodes", nodesTag); if(nodesTag) { // Node tag found, therefore it is a cluster. const cluster c = C.newCluster(rootCluster); m_clusterId[idAttr->getValue()] = c; if(!readCluster(G, C, CA, c, *nodesTag)) { return false; } } else { // Node tag not found, therefore it is "normal" node. const node v = G.newNode(); C.reassignNode(v, rootCluster); m_nodeId[idAttr->getValue()] = v; if(CA) { readAttributes(*CA, v, nodeTag); } } } return true; }