string XMLTree(Node *node, int level) { string xml, start, end; start = node->XMLStart(); end = node->XMLEnd(); for (int i = 0; i < level; ++i) { xml += ' '; } xml += start; xml += '\n'; for(Node::node_iterator it = node->begin(); it != node->end(); ++it) { Node *child = *it; xml += XMLTree(child, level + 1); } for (int i = 0; i < level; ++i) { xml += ' '; } xml += end; xml += '\n'; return xml; }
void MapLoader::LoadMap(STRARR& cmd) { if ( !cmd.size() ) cout<<"please specify map name: ldmap [mapname]\n"; else { string mappath = _working_dir + "/" + cmd[0]; _world.insert( std::pair<string, XMLTree>(cmd[0], XMLTree(mappath)) ); } }
int main2(int argc, char *argv[]) { Node *node = NodeFactory::create(N_TERM1); node->addChild(NodeFactory::create(N_TERM2)); node->addChild(NodeFactory::create(N_T1)); cout << XMLTree(node) << endl; return 0; }