13 std::string Indent(size_t size)
15 return std::string(level * 4, ' ');
18 std::string PrintAttr(const char ** attr)
25 if (*(attr + 1) == NULL)
27 res += std::string(" ") + *attr + "=\"" + *(attr + 1) + "\"";
33 void Start(void * data, const char * el, const char ** attr)
35 ParserState * state = static_cast<ParserState *>(data);
37 std::cout << Indent(state->level) << "<" << el << PrintAttrs(attr) << ">\n";
41 void End(void * data, const char * el)
43 ParserState * state = static_cast<ParserState *>(data);
45 std::cout << Indent(state->level) << "</" << el << ">\n";
51 void SGCONF::PrintXML(const std::string& xml)
53 ParserState state = { 0 };
55 XML_Parser parser = XML_ParserCreate(NULL);
56 XML_ParserReset(parser, NULL);
57 XML_SetElementHandler(parser, Start, End);
58 XML_SetUserData(parser, &state);
60 if (XML_Parse(parser, xml.c_str(), xml.length(), true) == XML_STATUS_ERROR)
61 std::cerr << "XML parse error at line " << XML_GetCurrentLineNumber(sc->parser)
62 << ": '" << XML_ErrorString(XML_GetErrorCode(sc->parser)) << "'"
65 XML_ParserFree(parser);