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