10 #include <libxml/encoding.h>
11 #include <libxml/xmlwriter.h>
18 using namespace libdap;
27 throw InternalErr(__FILE__, __LINE__,
"Error allocating the xml buffer");
29 xmlBufferSetAllocationScheme(d_doc_buf, XML_BUFFER_ALLOC_DOUBLEIT);
33 if (!(d_writer = xmlNewTextWriterMemory(d_doc_buf, 0)))
34 throw InternalErr(__FILE__, __LINE__,
"Error allocating memory for xml writer");
36 if (xmlTextWriterSetIndent(d_writer, pad.length()) < 0)
37 throw InternalErr(__FILE__, __LINE__,
"Error starting indentation for response document ");
39 if (xmlTextWriterSetIndentString(d_writer, (
const xmlChar*)pad.c_str()) < 0)
40 throw InternalErr(__FILE__, __LINE__,
"Error setting indentation for response document ");
48 if (xmlTextWriterStartDocument(d_writer, NULL,
ENCODING, NULL) < 0)
49 throw InternalErr(__FILE__, __LINE__,
"Error starting xml response document");
62 void XMLWriter::m_cleanup() {
65 xmlFreeTextWriter(d_writer);
72 xmlBufferFree(d_doc_buf);
81 if (d_writer && d_started) {
82 if (xmlTextWriterEndDocument(d_writer) < 0)
83 throw InternalErr(__FILE__, __LINE__,
"Error ending the document");
89 xmlFreeTextWriter(d_writer);
93 if (!d_doc_buf->content)
94 throw InternalErr(__FILE__, __LINE__,
"Error retrieving response document as string");
97 if (xmlTextWriterFlush(d_writer) < 0)
98 throw InternalErr(__FILE__, __LINE__,
"Error flushing the xml writer buffer");
101 return (
const char *)d_doc_buf->content;