33 #include <libxml/encoding.h> 34 #include <libxml/xmlwriter.h> 36 #include "XMLWriter.h" 37 #include "InternalErr.h" 40 const char *ENCODING =
"ISO-8859-1";
41 const int XML_BUF_SIZE = 2000000;
45 XMLWriter::XMLWriter(
const string &pad) {
51 if (!(d_doc_buf = xmlBufferCreateSize(XML_BUF_SIZE)))
52 throw InternalErr(__FILE__, __LINE__,
"Error allocating the xml buffer");
54 xmlBufferSetAllocationScheme(d_doc_buf, XML_BUFFER_ALLOC_DOUBLEIT);
58 if (!(d_writer = xmlNewTextWriterMemory(d_doc_buf, 0)))
59 throw InternalErr(__FILE__, __LINE__,
"Error allocating memory for xml writer");
61 if (xmlTextWriterSetIndent(d_writer, pad.length()) < 0)
62 throw InternalErr(__FILE__, __LINE__,
"Error starting indentation for response document ");
64 if (xmlTextWriterSetIndentString(d_writer, (
const xmlChar*)pad.c_str()) < 0)
65 throw InternalErr(__FILE__, __LINE__,
"Error setting indentation for response document ");
73 if (xmlTextWriterStartDocument(d_writer, NULL, ENCODING, NULL) < 0)
74 throw InternalErr(__FILE__, __LINE__,
"Error starting xml response document");
83 XMLWriter::~XMLWriter() {
87 void XMLWriter::m_cleanup() {
90 xmlFreeTextWriter(d_writer);
97 xmlBufferFree(d_doc_buf);
105 const char *XMLWriter::get_doc() {
106 if (d_writer && d_started) {
107 if (xmlTextWriterEndDocument(d_writer) < 0)
108 throw InternalErr(__FILE__, __LINE__,
"Error ending the document");
114 xmlFreeTextWriter(d_writer);
118 if (!d_doc_buf->content)
119 throw InternalErr(__FILE__, __LINE__,
"Error retrieving response document as string");
121 return (
const char *)d_doc_buf->content;
124 unsigned int XMLWriter::get_doc_size() {
125 if (d_writer && d_started) {
126 if (xmlTextWriterEndDocument(d_writer) < 0)
127 throw InternalErr(__FILE__, __LINE__,
"Error ending the document");
133 xmlFreeTextWriter(d_writer);
137 if (!d_doc_buf->content)
138 throw InternalErr(__FILE__, __LINE__,
"Error retrieving response document as string");
141 return d_doc_buf->use;
top level DAP object to house generic methods
A class for software fault reporting.