2012-07-18 21:59:03 +03:00
|
|
|
#pragma once
|
2006-08-03 17:49:57 +03:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
|
2006-09-05 00:06:23 +03:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using std::map;
|
|
|
|
using std::list;
|
2006-08-03 17:49:57 +03:00
|
|
|
|
|
|
|
|
|
|
|
typedef map<string, string> XMLAttrs;
|
|
|
|
|
|
|
|
|
|
|
|
class XMLWriter
|
|
|
|
{
|
|
|
|
private:
|
2014-02-26 19:55:18 +02:00
|
|
|
|
2006-09-05 00:06:23 +03:00
|
|
|
std::ostream & output;
|
2006-08-03 17:49:57 +03:00
|
|
|
|
2006-08-16 13:32:30 +03:00
|
|
|
bool indent;
|
2006-08-03 17:49:57 +03:00
|
|
|
bool closed;
|
|
|
|
|
|
|
|
list<string> pendingElems;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2006-09-05 00:06:23 +03:00
|
|
|
XMLWriter(bool indent, std::ostream & output);
|
2006-08-03 17:49:57 +03:00
|
|
|
~XMLWriter();
|
|
|
|
|
|
|
|
void close();
|
|
|
|
|
|
|
|
void openElement(const string & name,
|
|
|
|
const XMLAttrs & attrs = XMLAttrs());
|
|
|
|
void closeElement();
|
|
|
|
|
2006-08-03 18:52:09 +03:00
|
|
|
void writeEmptyElement(const string & name,
|
2006-08-03 17:49:57 +03:00
|
|
|
const XMLAttrs & attrs = XMLAttrs());
|
|
|
|
|
|
|
|
private:
|
|
|
|
void writeAttrs(const XMLAttrs & attrs);
|
2006-08-16 13:32:30 +03:00
|
|
|
|
2018-05-02 14:56:34 +03:00
|
|
|
void indent_(size_t depth);
|
2006-08-03 17:49:57 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class XMLOpenElement
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
XMLWriter & writer;
|
|
|
|
public:
|
|
|
|
XMLOpenElement(XMLWriter & writer, const string & name,
|
|
|
|
const XMLAttrs & attrs = XMLAttrs())
|
|
|
|
: writer(writer)
|
|
|
|
{
|
|
|
|
writer.openElement(name, attrs);
|
|
|
|
}
|
|
|
|
~XMLOpenElement()
|
|
|
|
{
|
|
|
|
writer.closeElement();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-02-26 19:55:18 +02:00
|
|
|
|
2006-09-05 00:06:23 +03:00
|
|
|
}
|