35 #include <libxml/encoding.h>
36 #include <libxml/xmlwriter.h>
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");
87 void XMLWriter::m_cleanup() {
90 xmlFreeTextWriter(d_writer);
97 xmlBufferFree(d_doc_buf);
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");
122 if (xmlTextWriterFlush(d_writer) < 0)
123 throw InternalErr(__FILE__, __LINE__,
"Error flushing the xml writer buffer");
126 return (
const char *)d_doc_buf->content;
130 if (d_writer && d_started) {
131 if (xmlTextWriterEndDocument(d_writer) < 0)
132 throw InternalErr(__FILE__, __LINE__,
"Error ending the document");
138 xmlFreeTextWriter(d_writer);
142 if (!d_doc_buf->content)
143 throw InternalErr(__FILE__, __LINE__,
"Error retrieving response document as string");
146 if (xmlTextWriterFlush(d_writer) < 0)
147 throw InternalErr(__FILE__, __LINE__,
"Error flushing the xml writer buffer");
151 return d_doc_buf->use;
A class for software fault reporting.
XMLWriter(const std::string &pad=" ")
unsigned int get_doc_size()