15 std::string Indent(size_t level)
17 return std::string(level * 4, ' ');
20 std::string PrintAttr(const char ** attr)
27 if (*(attr + 1) == NULL)
29 res += std::string(" ") + *attr + "=\"" + *(attr + 1) + "\"";
35 void Start(void * data, const char * el, const char ** attr)
37 ParserState * state = static_cast<ParserState *>(data);
39 std::cout << Indent(state->level) << "<" << el << PrintAttr(attr) << ">\n";
43 void End(void * data, const char * el)
45 ParserState * state = static_cast<ParserState *>(data);
48 std::cout << Indent(state->level) << "</" << el << ">\n";
53 void SGCONF::PrintXML(const std::string& xml)
55 ParserState state = { 0 };
57 XML_Parser parser = XML_ParserCreate(NULL);
58 XML_ParserReset(parser, NULL);
59 XML_SetElementHandler(parser, Start, End);
60 XML_SetUserData(parser, &state);
62 if (XML_Parse(parser, xml.c_str(), xml.length(), true) == XML_STATUS_ERROR)
63 std::cerr << "XML parse error at line " << XML_GetCurrentLineNumber(parser)
64 << ": '" << XML_ErrorString(XML_GetErrorCode(parser)) << "'"
67 XML_ParserFree(parser);