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