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) {
53 if (!(d_doc_buf = xmlBufferCreateSize(XML_BUF_SIZE)))
54 throw InternalErr(__FILE__, __LINE__,
"Error allocating the xml buffer");
56 xmlBufferSetAllocationScheme(d_doc_buf, XML_BUFFER_ALLOC_DOUBLEIT);
60 if (!(d_writer = xmlNewTextWriterMemory(d_doc_buf, 0)))
61 throw InternalErr(__FILE__, __LINE__,
"Error allocating memory for xml writer");
63 if (xmlTextWriterSetIndent(d_writer, pad.length()) < 0)
64 throw InternalErr(__FILE__, __LINE__,
"Error starting indentation for response document ");
66 if (xmlTextWriterSetIndentString(d_writer, (
const xmlChar*)pad.c_str()) < 0)
67 throw InternalErr(__FILE__, __LINE__,
"Error setting indentation for response document ");
75 if (xmlTextWriterStartDocument(d_writer, NULL, ENCODING, NULL) < 0)
76 throw InternalErr(__FILE__, __LINE__,
"Error starting xml response document");
85 XMLWriter::~XMLWriter() {
89 void XMLWriter::m_cleanup() {
92 xmlFreeTextWriter(d_writer);
99 xmlBufferFree(d_doc_buf);
107 const char *XMLWriter::get_doc() {
108 if (d_writer && d_started) {
109 if (xmlTextWriterEndDocument(d_writer) < 0)
110 throw InternalErr(__FILE__, __LINE__,
"Error ending the document");
116 xmlFreeTextWriter(d_writer);
120 if (!d_doc_buf->content)
121 throw InternalErr(__FILE__, __LINE__,
"Error retrieving response document as string");
123 return (
const char *)d_doc_buf->content;
126 unsigned int XMLWriter::get_doc_size() {
127 if (d_writer && d_started) {
128 if (xmlTextWriterEndDocument(d_writer) < 0)
129 throw InternalErr(__FILE__, __LINE__,
"Error ending the document");
135 xmlFreeTextWriter(d_writer);
139 if (!d_doc_buf->content)
140 throw InternalErr(__FILE__, __LINE__,
"Error retrieving response document as string");
143 return d_doc_buf->use;
top level DAP object to house generic methods
A class for software fault reporting.