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 {
|
|
|
|
|
2006-08-03 17:49:57 +03:00
|
|
|
|
2022-02-25 14:39:38 +02:00
|
|
|
typedef std::map<std::string, std::string> XMLAttrs;
|
2006-08-03 17:49:57 +03:00
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2022-02-25 14:39:38 +02:00
|
|
|
std::list<std::string> pendingElems;
|
2006-08-03 17:49:57 +03:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2022-02-25 14:39:38 +02:00
|
|
|
void openElement(std::string_view name,
|
2006-08-03 17:49:57 +03:00
|
|
|
const XMLAttrs & attrs = XMLAttrs());
|
|
|
|
void closeElement();
|
|
|
|
|
2022-02-25 14:39:38 +02:00
|
|
|
void writeEmptyElement(std::string_view 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:
|
2022-02-25 14:39:38 +02:00
|
|
|
XMLOpenElement(XMLWriter & writer, std::string_view name,
|
2006-08-03 17:49:57 +03:00
|
|
|
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
|
|
|
}
|