2006-08-03 16:49:57 +02:00
|
|
|
#ifndef __XML_WRITER_H
|
|
|
|
#define __XML_WRITER_H
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
typedef map<string, string> XMLAttrs;
|
|
|
|
|
|
|
|
|
|
|
|
class XMLWriter
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
ostream & output;
|
|
|
|
|
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-08-16 12:32:30 +02:00
|
|
|
XMLWriter(bool indent, 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());
|
|
|
|
|
|
|
|
void writeCharData(const string & data);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void writeAttrs(const XMLAttrs & attrs);
|
2006-08-16 12:32:30 +02:00
|
|
|
|
|
|
|
void indent_(unsigned int 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();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* !__XML_WRITER_H */
|