5 #include "xmlwriter.hpp"
7 XmlWriter::XmlWriter(std::ostream& outstream)
8 : out(outstream), indent(0)
12 XmlWriter::~XmlWriter()
14 if(sections.size() > 0) {
15 std::cerr << "WARNING: NOT CLOSED: ";
16 for(std::vector<std::string>::iterator i = sections.begin();
17 i != sections.end(); ++i)
18 std::cerr << *i << " ";
25 void XmlWriter::openTag(const char* name)
32 sections.push_back(name);
35 void XmlWriter::closeTag(const char* name)
37 if(sections.size() == 0)
38 throw std::runtime_error("got closeSection without prior openSection.");
40 const std::string& lastsection = sections.back();
41 if (lastsection != name) {
42 std::ostringstream msg;
43 msg << "mismatch in open/closeSection. Expected '"
44 << lastsection << "' got '" << name << "'";
45 throw std::runtime_error(msg.str());
51 // XXX: We should check for consistency here
56 void XmlWriter::writeTag(const char* name)
64 void XmlWriter::newLine()
68 for (int i=0;i<indent;i++)
73 void XmlWriter::closeTag()
76 out << closetag << "\n";