xmlwriter.c revision 75e389d4e0ccd998d288387051e66a8f0b2af1b0
15841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
21d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/*
31d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlwriter.c: XML text writer implementation
41d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
51d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * For license and disclaimer see the license and disclaimer of
61d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * libxml2.
71d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
81d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * alfred@mickautsch.de
91d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
11b23de5ad89fbcd0a0a6dcab2053cb8e25fc7aa0fIgor Zlatkovic#define IN_LIBXML
121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard#include <string.h>
131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard#include "libxml.h"
151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard#include <libxml/xmlmemory.h>
161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard#include <libxml/parser.h>
175841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard#include <libxml/uri.h>
185841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard#include <libxml/HTMLtree.h>
191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard#ifdef LIBXML_WRITER_ENABLED
211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard#include <libxml/xmlwriter.h>
231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard#define B64LINELEN 72
251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard#define B64CRLF "\r\n"
261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/*
281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Types are kept private
291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardtypedef enum {
311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    XML_TEXTWRITER_NONE = 0,
321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    XML_TEXTWRITER_NAME,
331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    XML_TEXTWRITER_ATTRIBUTE,
341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    XML_TEXTWRITER_TEXT,
351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    XML_TEXTWRITER_PI,
361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    XML_TEXTWRITER_PI_TEXT,
371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    XML_TEXTWRITER_CDATA,
381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    XML_TEXTWRITER_DTD,
391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    XML_TEXTWRITER_DTD_TEXT,
401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    XML_TEXTWRITER_DTD_ELEM,
41500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    XML_TEXTWRITER_DTD_ELEM_TEXT,
421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    XML_TEXTWRITER_DTD_ATTL,
43500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    XML_TEXTWRITER_DTD_ATTL_TEXT,
44500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    XML_TEXTWRITER_DTD_ENTY,    /* entity */
45500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    XML_TEXTWRITER_DTD_ENTY_TEXT,
46500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    XML_TEXTWRITER_DTD_PENT,    /* parameter entity */
4787640d5f14e7ce8b9844b886c765af0c56de5ca5William M. Brack    XML_TEXTWRITER_COMMENT
481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard} xmlTextWriterState;
491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardtypedef struct _xmlTextWriterStackEntry xmlTextWriterStackEntry;
511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardstruct _xmlTextWriterStackEntry {
531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlChar *name;
541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterState state;
551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard};
561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardtypedef struct _xmlTextWriterNsStackEntry xmlTextWriterNsStackEntry;
581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardstruct _xmlTextWriterNsStackEntry {
591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlChar *prefix;
601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlChar *uri;
611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlLinkPtr elem;
621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard};
631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardstruct _xmlTextWriter {
65ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    xmlOutputBufferPtr out;     /* output buffer */
66ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    xmlListPtr nodes;           /* element name stack */
67ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    xmlListPtr nsstack;         /* name spaces stack */
681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int level;
69ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    int indent;                 /* enable indent */
70ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    int doindent;               /* internal indent flag */
71ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    xmlChar *ichar;             /* indent character */
72ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    char qchar;                 /* character used for quoting attribute values */
7320c5e7878d462bfd93aa4eede7f1f5faabd377feDaniel Veillard    xmlParserCtxtPtr ctxt;
74a521d287516f2dc93a8fe540c5883ffc39cb5024Daniel Veillard    int no_doc_free;
751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard};
761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardstatic void xmlFreeTextWriterStackEntry(xmlLinkPtr lk);
781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardstatic int xmlCmpTextWriterStackEntry(const void *data0,
791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                      const void *data1);
801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardstatic void xmlFreeTextWriterNsStackEntry(xmlLinkPtr lk);
811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardstatic int xmlCmpTextWriterNsStackEntry(const void *data0,
821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                        const void *data1);
831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardstatic int xmlTextWriterWriteMemCallback(void *context,
841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                         const xmlChar * str, int len);
851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardstatic int xmlTextWriterCloseMemCallback(void *context);
865841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillardstatic int xmlTextWriterWriteDocCallback(void *context,
875841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                                         const xmlChar * str, int len);
885841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillardstatic int xmlTextWriterCloseDocCallback(void *context);
895841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardstatic xmlChar *xmlTextWriterVSprintf(const char *format, va_list argptr);
911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardstatic int xmlOutputBufferWriteBase64(xmlOutputBufferPtr out, int len,
921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                      const unsigned char *data);
935841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillardstatic void xmlTextWriterStartDocumentCallback(void *ctx);
94ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillardstatic int xmlTextWriterWriteIndent(xmlTextWriterPtr writer);
95500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillardstatic int
96500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard  xmlTextWriterHandleStateDependencies(xmlTextWriterPtr writer,
97500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                                       xmlTextWriterStackEntry * p);
981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
100dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard * xmlWriterErrMsg:
101dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard * @ctxt:  a writer context
102dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard * @error:  the error number
103dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard * @msg:  the error message
104dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard *
105dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard * Handle a writer error
106dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard */
107dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillardstatic void
108dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel VeillardxmlWriterErrMsg(xmlTextWriterPtr ctxt, xmlParserErrors error,
109dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard               const char *msg)
110dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard{
111dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard    if (ctxt != NULL) {
112dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard	__xmlRaiseError(NULL, NULL, NULL, ctxt->ctxt,
113dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard	            NULL, XML_FROM_WRITER, error, XML_ERR_FATAL,
114dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard		    NULL, 0, NULL, NULL, NULL, 0, 0, msg);
115dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard    } else {
116dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard	__xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_WRITER, error,
117dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard                    XML_ERR_FATAL, NULL, 0, NULL, NULL, NULL, 0, 0, msg);
118dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard    }
119dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard}
120dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard
121dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard/**
122dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard * xmlWriterErrMsgInt:
123dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard * @ctxt:  a writer context
124dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard * @error:  the error number
125dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard * @msg:  the error message
126dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard * @val:  an int
127dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard *
128dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard * Handle a writer error
129dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard */
130dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillardstatic void
131dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel VeillardxmlWriterErrMsgInt(xmlTextWriterPtr ctxt, xmlParserErrors error,
132dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard               const char *msg, int val)
133dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard{
134dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard    if (ctxt != NULL) {
135dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard	__xmlRaiseError(NULL, NULL, NULL, ctxt->ctxt,
136dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard	            NULL, XML_FROM_WRITER, error, XML_ERR_FATAL,
137dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard		    NULL, 0, NULL, NULL, NULL, val, 0, msg, val);
138dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard    } else {
139dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard	__xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_WRITER, error,
140dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard                    XML_ERR_FATAL, NULL, 0, NULL, NULL, NULL, val, 0, msg, val);
141dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard    }
142dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard}
143dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard
144dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard/**
1451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlNewTextWriter:
1461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @out:  an xmlOutputBufferPtr
1471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
1481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Create a new xmlNewTextWriter structure using an xmlOutputBufferPtr
149d5cc0f7f5185532120f6b8351e12ed7e81d4a28cDaniel Veillard * NOTE: the @out parameter will be deallocated when the writer is closed
150d5cc0f7f5185532120f6b8351e12ed7e81d4a28cDaniel Veillard *       (if the call succeed.)
1511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
1521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the new xmlTextWriterPtr or NULL in case of error
1531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
1541d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterPtr
1551d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlNewTextWriter(xmlOutputBufferPtr out)
1561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
1571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterPtr ret;
1581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
1591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    ret = (xmlTextWriterPtr) xmlMalloc(sizeof(xmlTextWriter));
1601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (ret == NULL) {
161dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
1621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        "xmlNewTextWriter : out of memory!\n");
1631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return NULL;
1641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
1651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    memset(ret, 0, (size_t) sizeof(xmlTextWriter));
1661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
1671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    ret->nodes = xmlListCreate((xmlListDeallocator)
1681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                               xmlFreeTextWriterStackEntry,
1691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                               (xmlListDataCompare)
1701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                               xmlCmpTextWriterStackEntry);
1711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (ret->nodes == NULL) {
172dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
1731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        "xmlNewTextWriter : out of memory!\n");
1741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlFree(ret);
1751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return NULL;
1761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
1771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
1781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    ret->nsstack = xmlListCreate((xmlListDeallocator)
1791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                 xmlFreeTextWriterNsStackEntry,
1801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                 (xmlListDataCompare)
1811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                 xmlCmpTextWriterNsStackEntry);
1821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (ret->nsstack == NULL) {
183dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
1841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        "xmlNewTextWriter : out of memory!\n");
185500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        xmlListDelete(ret->nodes);
1861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlFree(ret);
1871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return NULL;
1881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
1891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
1901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    ret->out = out;
191ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    ret->ichar = xmlStrdup(BAD_CAST " ");
1921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    ret->qchar = '"';
1931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
194500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (!ret->ichar) {
195500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        xmlListDelete(ret->nodes);
196500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        xmlListDelete(ret->nsstack);
197500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        xmlFree(ret);
198dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
199500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        "xmlNewTextWriter : out of memory!\n");
200ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        return NULL;
201500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
202a521d287516f2dc93a8fe540c5883ffc39cb5024Daniel Veillard    ret->no_doc_free = 0;
203ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
2041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return ret;
2051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
2061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
2071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
2081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlNewTextWriterFilename:
2091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @uri:  the URI of the resource for the output
2101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @compression:  compress the output?
2111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
2121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Create a new xmlNewTextWriter structure with @uri as output
2131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
2141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the new xmlTextWriterPtr or NULL in case of error
2151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
2161d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterPtr
2171d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlNewTextWriterFilename(const char *uri, int compression)
2181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
2191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterPtr ret;
2201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlOutputBufferPtr out;
2211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
2221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    out = xmlOutputBufferCreateFilename(uri, NULL, compression);
2231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (out == NULL) {
224dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
2251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        "xmlNewTextWriterFilename : out of memory!\n");
2261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return NULL;
2271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
2281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
2291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    ret = xmlNewTextWriter(out);
2301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (ret == NULL) {
231dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
2321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        "xmlNewTextWriterFilename : out of memory!\n");
2331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlOutputBufferClose(out);
2341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return NULL;
2351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
2361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
2372cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard    ret->indent = 0;
2382cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard    ret->doindent = 0;
2391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return ret;
2401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
2411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
2421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
2431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlNewTextWriterMemory:
2441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @buf:  xmlBufferPtr
2451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @compression:  compress the output?
2461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
2471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Create a new xmlNewTextWriter structure with @buf as output
2481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * TODO: handle compression
2491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
2501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the new xmlTextWriterPtr or NULL in case of error
2511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
2521d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterPtr
2531d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlNewTextWriterMemory(xmlBufferPtr buf, int compression ATTRIBUTE_UNUSED)
2541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
2551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterPtr ret;
2561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlOutputBufferPtr out;
2571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
2581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/*::todo handle compression */
2591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    out = xmlOutputBufferCreateIO((xmlOutputWriteCallback)
2601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                  xmlTextWriterWriteMemCallback,
2611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                  (xmlOutputCloseCallback)
2621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                  xmlTextWriterCloseMemCallback,
2631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                  (void *) buf, NULL);
2641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (out == NULL) {
265dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
2661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        "xmlNewTextWriterMemory : out of memory!\n");
2671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return NULL;
2681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
2691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
2701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    ret = xmlNewTextWriter(out);
2711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (ret == NULL) {
272dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
2731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        "xmlNewTextWriterMemory : out of memory!\n");
2741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlOutputBufferClose(out);
2751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return NULL;
2761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
2771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
2781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return ret;
2791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
2801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
2811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
2825841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * xmlNewTextWriterPushParser:
2835841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @ctxt: xmlParserCtxtPtr to hold the new XML document tree
2845841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @compression:  compress the output?
2855841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
2865841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Create a new xmlNewTextWriter structure with @ctxt as output
287d5cc0f7f5185532120f6b8351e12ed7e81d4a28cDaniel Veillard * NOTE: the @ctxt context will be freed with the resulting writer
288d5cc0f7f5185532120f6b8351e12ed7e81d4a28cDaniel Veillard *       (if the call succeeds).
2895841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * TODO: handle compression
2905841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
2915841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Returns the new xmlTextWriterPtr or NULL in case of error
2925841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard */
2935841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel VeillardxmlTextWriterPtr
2941d913863130a17a638db69c2c50f89e5b0d4aae4Daniel VeillardxmlNewTextWriterPushParser(xmlParserCtxtPtr ctxt,
2951d913863130a17a638db69c2c50f89e5b0d4aae4Daniel Veillard                           int compression ATTRIBUTE_UNUSED)
2965841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard{
2975841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    xmlTextWriterPtr ret;
2985841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    xmlOutputBufferPtr out;
2995841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
300500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (ctxt == NULL) {
301dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
302500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        "xmlNewTextWriterPushParser : invalid context!\n");
303500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        return NULL;
304500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
305500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3065841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    out = xmlOutputBufferCreateIO((xmlOutputWriteCallback)
3075841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                                  xmlTextWriterWriteDocCallback,
3085841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                                  (xmlOutputCloseCallback)
3095841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                                  xmlTextWriterCloseDocCallback,
3105841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                                  (void *) ctxt, NULL);
3115841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    if (out == NULL) {
312dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
3135841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                        "xmlNewTextWriterPushParser : error at xmlOutputBufferCreateIO!\n");
3145841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        return NULL;
3155841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    }
3165841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
3175841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    ret = xmlNewTextWriter(out);
3185841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    if (ret == NULL) {
319dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
3205841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                        "xmlNewTextWriterPushParser : error at xmlNewTextWriter!\n");
3215841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        xmlOutputBufferClose(out);
3225841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        return NULL;
3235841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    }
3245841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
32520c5e7878d462bfd93aa4eede7f1f5faabd377feDaniel Veillard    ret->ctxt = ctxt;
32620c5e7878d462bfd93aa4eede7f1f5faabd377feDaniel Veillard
3275841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    return ret;
3285841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard}
3295841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
3305841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard/**
3315841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * xmlNewTextWriterDoc:
3325841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @doc: address of a xmlDocPtr to hold the new XML document tree
3335841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @compression:  compress the output?
3345841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
3355841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Create a new xmlNewTextWriter structure with @*doc as output
3365841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
3375841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Returns the new xmlTextWriterPtr or NULL in case of error
3385841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard */
3395841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel VeillardxmlTextWriterPtr
3405841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel VeillardxmlNewTextWriterDoc(xmlDocPtr * doc, int compression)
3415841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard{
3425841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    xmlTextWriterPtr ret;
3435841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    xmlSAXHandler saxHandler;
3445841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    xmlParserCtxtPtr ctxt;
3455841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
3465841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    memset(&saxHandler, '\0', sizeof(saxHandler));
3475841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    xmlSAX2InitDefaultSAXHandler(&saxHandler, 1);
3485841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    saxHandler.startDocument = xmlTextWriterStartDocumentCallback;
3495841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    saxHandler.startElement = xmlSAX2StartElement;
3505841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    saxHandler.endElement = xmlSAX2EndElement;
3515841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
3525841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    ctxt = xmlCreatePushParserCtxt(&saxHandler, NULL, NULL, 0, NULL);
3535841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    if (ctxt == NULL) {
354dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
3555841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                        "xmlNewTextWriterDoc : error at xmlCreatePushParserCtxt!\n");
3565841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        return NULL;
3575841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    }
35803a53c34db279cbe4a305d58969beb1f26ff3d19Daniel Veillard    /*
35903a53c34db279cbe4a305d58969beb1f26ff3d19Daniel Veillard     * For some reason this seems to completely break if node names
36003a53c34db279cbe4a305d58969beb1f26ff3d19Daniel Veillard     * are interned.
36103a53c34db279cbe4a305d58969beb1f26ff3d19Daniel Veillard     */
36203a53c34db279cbe4a305d58969beb1f26ff3d19Daniel Veillard    ctxt->dictNames = 0;
3635841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
3641d913863130a17a638db69c2c50f89e5b0d4aae4Daniel Veillard    ctxt->myDoc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION);
3655841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    if (ctxt->myDoc == NULL) {
3665841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        xmlFreeParserCtxt(ctxt);
367dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
3685841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                        "xmlNewTextWriterDoc : error at xmlNewDoc!\n");
3695841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        return NULL;
3705841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    }
3715841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
3725841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    ret = xmlNewTextWriterPushParser(ctxt, compression);
3735841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    if (ret == NULL) {
374dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
3755841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                        "xmlNewTextWriterDoc : error at xmlNewTextWriterPushParser!\n");
3765841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        return NULL;
3775841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    }
3785841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
379500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    xmlSetDocCompressMode(ctxt->myDoc, compression);
380500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
381a521d287516f2dc93a8fe540c5883ffc39cb5024Daniel Veillard    if (doc != NULL) {
382500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        *doc = ctxt->myDoc;
383a521d287516f2dc93a8fe540c5883ffc39cb5024Daniel Veillard	ret->no_doc_free = 1;
384a521d287516f2dc93a8fe540c5883ffc39cb5024Daniel Veillard    }
3855841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
3865841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    return ret;
3875841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard}
3885841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
3895841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard/**
3905841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * xmlNewTextWriterTree:
3915841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @doc: xmlDocPtr
3925841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @node: xmlNodePtr or NULL for doc->children
3935841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @compression:  compress the output?
3945841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
3955841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Create a new xmlNewTextWriter structure with @doc as output
3965841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * starting at @node
3975841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
3985841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Returns the new xmlTextWriterPtr or NULL in case of error
3995841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard */
4005841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel VeillardxmlTextWriterPtr
4015841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel VeillardxmlNewTextWriterTree(xmlDocPtr doc, xmlNodePtr node, int compression)
4025841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard{
4035841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    xmlTextWriterPtr ret;
4045841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    xmlSAXHandler saxHandler;
4055841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    xmlParserCtxtPtr ctxt;
4065841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
4075841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    if (doc == NULL) {
408dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
409500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        "xmlNewTextWriterTree : invalid document tree!\n");
4105841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        return NULL;
4115841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    }
4125841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
4135841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    memset(&saxHandler, '\0', sizeof(saxHandler));
4145841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    xmlSAX2InitDefaultSAXHandler(&saxHandler, 1);
4155841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    saxHandler.startDocument = xmlTextWriterStartDocumentCallback;
4165841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    saxHandler.startElement = xmlSAX2StartElement;
4175841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    saxHandler.endElement = xmlSAX2EndElement;
4185841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
4195841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    ctxt = xmlCreatePushParserCtxt(&saxHandler, NULL, NULL, 0, NULL);
4205841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    if (ctxt == NULL) {
421dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
4225841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                        "xmlNewTextWriterDoc : error at xmlCreatePushParserCtxt!\n");
4235841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        return NULL;
4245841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    }
42503a53c34db279cbe4a305d58969beb1f26ff3d19Daniel Veillard    /*
42603a53c34db279cbe4a305d58969beb1f26ff3d19Daniel Veillard     * For some reason this seems to completely break if node names
42703a53c34db279cbe4a305d58969beb1f26ff3d19Daniel Veillard     * are interned.
42803a53c34db279cbe4a305d58969beb1f26ff3d19Daniel Veillard     */
42903a53c34db279cbe4a305d58969beb1f26ff3d19Daniel Veillard    ctxt->dictNames = 0;
4305841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
4315841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    ret = xmlNewTextWriterPushParser(ctxt, compression);
4325841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    if (ret == NULL) {
433500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        xmlFreeParserCtxt(ctxt);
434dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
4355841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                        "xmlNewTextWriterDoc : error at xmlNewTextWriterPushParser!\n");
4365841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        return NULL;
4375841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    }
4385841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
439500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    ctxt->myDoc = doc;
440500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    ctxt->node = node;
441a521d287516f2dc93a8fe540c5883ffc39cb5024Daniel Veillard    ret->no_doc_free = 1;
442500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
4435841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    xmlSetDocCompressMode(doc, compression);
4445841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
4455841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    return ret;
4465841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard}
4475841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
4485841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard/**
4491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlFreeTextWriter:
4501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
4511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
4521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Deallocate all the resources associated to the writer
4531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
4541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardvoid
4551d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlFreeTextWriter(xmlTextWriterPtr writer)
4561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
4571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL)
4581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return;
4591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
4601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer->out != NULL)
4611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlOutputBufferClose(writer->out);
4621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
4631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer->nodes != NULL)
4641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlListDelete(writer->nodes);
4651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
4661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer->nsstack != NULL)
4671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlListDelete(writer->nsstack);
4681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
469a521d287516f2dc93a8fe540c5883ffc39cb5024Daniel Veillard    if (writer->ctxt != NULL) {
470a521d287516f2dc93a8fe540c5883ffc39cb5024Daniel Veillard        if ((writer->ctxt->myDoc != NULL) && (writer->no_doc_free == 0)) {
471a521d287516f2dc93a8fe540c5883ffc39cb5024Daniel Veillard	    xmlFreeDoc(writer->ctxt->myDoc);
472a521d287516f2dc93a8fe540c5883ffc39cb5024Daniel Veillard	    writer->ctxt->myDoc = NULL;
473a521d287516f2dc93a8fe540c5883ffc39cb5024Daniel Veillard	}
47420c5e7878d462bfd93aa4eede7f1f5faabd377feDaniel Veillard        xmlFreeParserCtxt(writer->ctxt);
475a521d287516f2dc93a8fe540c5883ffc39cb5024Daniel Veillard    }
47620c5e7878d462bfd93aa4eede7f1f5faabd377feDaniel Veillard
4774773df2a58be83e1b9b1b55840371acf37386820Daniel Veillard    if (writer->ichar != NULL)
4784773df2a58be83e1b9b1b55840371acf37386820Daniel Veillard        xmlFree(writer->ichar);
4791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlFree(writer);
4801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
4811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
4821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
4831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterStartDocument:
4841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
4851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @version:  the xml version ("1.0") or NULL for default ("1.0")
4861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @encoding:  the encoding or NULL for default
4871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @standalone: "yes" or "no" or NULL for default
4881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
4891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Start a new xml document
4901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
4911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
4921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
4931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
4941d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterStartDocument(xmlTextWriterPtr writer, const char *version,
4951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                           const char *encoding, const char *standalone)
4961d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
4971d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
4981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
4991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlLinkPtr lk;
5001d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlCharEncodingHandlerPtr encoder;
5011d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
502500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if ((writer == NULL) || (writer->out == NULL)) {
503dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
504500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        "xmlTextWriterStartDocument : invalid writer!\n");
5051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
506500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
5071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
5081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    lk = xmlListFront(writer->nodes);
5091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if ((lk != NULL) && (xmlLinkGetData(lk) != NULL)) {
510dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
511500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        "xmlTextWriterStartDocument : not allowed in this context!\n");
5121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
5131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
5141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
5151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    encoder = NULL;
5161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (encoding != NULL) {
5171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        encoder = xmlFindCharEncodingHandler(encoding);
5181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (encoder == NULL) {
519dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard            xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
5201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                            "xmlTextWriterStartDocument : out of memory!\n");
5211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
5221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        }
5231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
5241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
5251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    writer->out->encoder = encoder;
5261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (encoder != NULL) {
5271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        writer->out->conv = xmlBufferCreateSize(4000);
5281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlCharEncOutFunc(encoder, writer->out->conv, NULL);
5291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    } else
5301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        writer->out->conv = NULL;
5311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
5321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
5331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlOutputBufferWriteString(writer->out, "<?xml version=");
5341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
5351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
5361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
5371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
5381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
5391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
5401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
5411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (version != 0)
5421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlOutputBufferWriteString(writer->out, version);
5431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    else
5441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlOutputBufferWriteString(writer->out, "1.0");
5451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
5461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
5471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
5481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
5491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
5501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
5511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
5521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer->out->encoder != 0) {
5531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlOutputBufferWriteString(writer->out, " encoding=");
5541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
5551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
5561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
5571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
5581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
5591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
5601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
5611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count =
5621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            xmlOutputBufferWriteString(writer->out,
5631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                       writer->out->encoder->name);
5641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
5651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
5661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
5671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
5681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
5691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
5701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
5711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
5721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
5731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (standalone != 0) {
5741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlOutputBufferWriteString(writer->out, " standalone=");
5751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
5761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
5771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
5781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
5791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
5801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
5811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
5821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlOutputBufferWriteString(writer->out, standalone);
5831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
5841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
5851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
5861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
5871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
5881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
5891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
5901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
5911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
5921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlOutputBufferWriteString(writer->out, "?>\n");
5931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
5941d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
5951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
5961d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
5971d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
5981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
5991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
6001d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
6011d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterEndDocument:
6021d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
6031d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
6041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * End an xml document. All open elements are closed
6051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
6061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
6071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
6081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
6091d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterEndDocument(xmlTextWriterPtr writer)
6101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
6111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
6121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
6131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlLinkPtr lk;
6141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterStackEntry *p;
6151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
616500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (writer == NULL) {
617dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
618500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        "xmlTextWriterEndDocument : invalid writer!\n");
6191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
620500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
6211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
6221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
6231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    while ((lk = xmlListFront(writer->nodes)) != NULL) {
6241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
6251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (p == 0)
6261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            break;
6271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        switch (p->state) {
6281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            case XML_TEXTWRITER_NAME:
6291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            case XML_TEXTWRITER_ATTRIBUTE:
6301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            case XML_TEXTWRITER_TEXT:
6311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                count = xmlTextWriterEndElement(writer);
6321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                if (count < 0)
6331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    return -1;
6341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                sum += count;
6351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                break;
6361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            case XML_TEXTWRITER_PI:
6371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            case XML_TEXTWRITER_PI_TEXT:
6381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                count = xmlTextWriterEndPI(writer);
6391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                if (count < 0)
6401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    return -1;
6411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                sum += count;
6421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                break;
6431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            case XML_TEXTWRITER_CDATA:
6441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                count = xmlTextWriterEndCDATA(writer);
6451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                if (count < 0)
6461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    return -1;
6471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                sum += count;
6481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                break;
6491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            case XML_TEXTWRITER_DTD:
650500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD_TEXT:
651500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD_ELEM:
652500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD_ELEM_TEXT:
653500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD_ATTL:
654500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD_ATTL_TEXT:
655500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD_ENTY:
656500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD_ENTY_TEXT:
657500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD_PENT:
6581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                count = xmlTextWriterEndDTD(writer);
6591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                if (count < 0)
6601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    return -1;
6611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                sum += count;
6621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                break;
663ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard            case XML_TEXTWRITER_COMMENT:
664ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                count = xmlTextWriterEndComment(writer);
665ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                if (count < 0)
666ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                    return -1;
667ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                sum += count;
668ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                break;
6691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            default:
670ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                break;
6711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        }
6721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
6731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
6742cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard    if (!writer->indent) {
675ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        count = xmlOutputBufferWriteString(writer->out, "\n");
676ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        if (count < 0)
677ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard            return -1;
678ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        sum += count;
679ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    }
680ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    return sum;
681ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard}
682ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
683ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard/**
684ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard * xmlTextWriterStartComment:
685ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard * @writer:  the xmlTextWriterPtr
686ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard *
687ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard * Start an xml comment.
688ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard *
689ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
690ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard */
691ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillardint
692ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel VeillardxmlTextWriterStartComment(xmlTextWriterPtr writer)
693ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard{
694ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    int count;
695ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    int sum;
696ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    xmlLinkPtr lk;
697ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    xmlTextWriterStackEntry *p;
698ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
699500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (writer == NULL) {
700dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
701500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        "xmlTextWriterStartComment : invalid writer!\n");
702ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        return -1;
703500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
704ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
705ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    sum = 0;
706ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    lk = xmlListFront(writer->nodes);
707ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    if (lk != 0) {
708ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
709ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        if (p != 0) {
710ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard            switch (p->state) {
711ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                case XML_TEXTWRITER_TEXT:
712ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                case XML_TEXTWRITER_NONE:
713ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                    break;
714ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                case XML_TEXTWRITER_NAME:
715ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                    count = xmlOutputBufferWriteString(writer->out, ">");
716ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                    if (count < 0)
717ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                        return -1;
718ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                    sum += count;
719500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    if (writer->indent) {
720500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        count =
721500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                            xmlOutputBufferWriteString(writer->out, "\n");
722500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        if (count < 0)
723500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                            return -1;
724500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        sum += count;
725500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    }
726ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                    p->state = XML_TEXTWRITER_TEXT;
727ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                    break;
728ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                default:
729ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                    return -1;
730ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard            }
731ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        }
732ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    }
733ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
734ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    p = (xmlTextWriterStackEntry *)
735ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        xmlMalloc(sizeof(xmlTextWriterStackEntry));
736ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    if (p == 0) {
737dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
738ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                        "xmlTextWriterStartElement : out of memory!\n");
739ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        return -1;
740ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    }
741ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
74275e389d4e0ccd998d288387051e66a8f0b2af1b0Daniel Veillard    p->name = NULL;
743ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    p->state = XML_TEXTWRITER_COMMENT;
744ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
745ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    xmlListPushFront(writer->nodes, p);
746ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
747ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    if (writer->indent) {
748ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        count = xmlTextWriterWriteIndent(writer);
749ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        if (count < 0)
750ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard            return -1;
751ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        sum += count;
752ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    }
753ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
754ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    count = xmlOutputBufferWriteString(writer->out, "<!--");
755ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    if (count < 0)
7565841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        return -1;
7575841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    sum += count;
758ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
759ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    return sum;
760ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard}
761ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
762ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard/**
763ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard * xmlTextWriterEndComment:
764ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard * @writer:  the xmlTextWriterPtr
765ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard *
766ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard * End the current xml coment.
767ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard *
768ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
769ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard */
770ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillardint
771ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel VeillardxmlTextWriterEndComment(xmlTextWriterPtr writer)
772ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard{
773ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    int count;
774ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    int sum;
775ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    xmlLinkPtr lk;
776ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    xmlTextWriterStackEntry *p;
777ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
778500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (writer == NULL) {
779dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
780500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        "xmlTextWriterEndComment : invalid writer!\n");
781ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        return -1;
782500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
783ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
784ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    lk = xmlListFront(writer->nodes);
785500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (lk == 0) {
786dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
787500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        "xmlTextWriterEndComment : not allowed in this context!\n");
788ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        return -1;
789500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
790ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
791ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
792ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    if (p == 0)
793ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        return -1;
794ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
795ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    sum = 0;
796ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    switch (p->state) {
797ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        case XML_TEXTWRITER_COMMENT:
798ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard            count = xmlOutputBufferWriteString(writer->out, "-->");
799ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard            if (count < 0)
800ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                return -1;
801ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard            sum += count;
802ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard            break;
803ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        default:
804ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard            return -1;
805ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    }
806ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
807ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    if (writer->indent) {
808ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        count = xmlOutputBufferWriteString(writer->out, "\n");
809ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        if (count < 0)
810ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard            return -1;
811ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        sum += count;
8122cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard    }
813ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
814ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    xmlListPopFront(writer->nodes);
8151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
8161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
8171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
8181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
8191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteFormatComment:
8201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
8211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @format:  format string (see printf)
8221d913863130a17a638db69c2c50f89e5b0d4aae4Daniel Veillard * @...:  extra parameters for the format
8231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
8241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write an xml comment.
8251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
8261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
8271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
828ffa3c74933baa45bef5e0d7f15473c38a4c3f9e8Daniel Veillardint XMLCDECL
8291d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteFormatComment(xmlTextWriterPtr writer,
8301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                const char *format, ...)
8311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
8321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
8331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_list ap;
8341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
8351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_start(ap, format);
8361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
8371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteVFormatComment(writer, format, ap);
8381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
8391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_end(ap);
8401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
8411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
8421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
8431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
8441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteVFormatComment:
8451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
8461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @format:  format string (see printf)
8471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @argptr:  pointer to the first member of the variable argument list.
8481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
8491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write an xml comment.
8501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
8511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
8521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
8531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
8541d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteVFormatComment(xmlTextWriterPtr writer,
8551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                 const char *format, va_list argptr)
8561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
8571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
8581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlChar *buf;
8591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
860500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (writer == NULL) {
861dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
862500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        "xmlTextWriterWriteVFormatComment : invalid writer!\n");
8631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
864500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
8651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
8661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    buf = xmlTextWriterVSprintf(format, argptr);
8671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (buf == 0)
8681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return 0;
8691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
8701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteComment(writer, buf);
8711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
8721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlFree(buf);
8731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
8741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
8751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
8761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
8771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteComment:
8781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
8791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @content:  comment string
8801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
8811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write an xml comment.
8821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
8831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
8841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
8851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
8861d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteComment(xmlTextWriterPtr writer, const xmlChar * content)
8871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
8881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
8891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
8901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
8911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
892ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    count = xmlTextWriterStartComment(writer);
8931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
8941d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
8951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
896ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    count = xmlTextWriterWriteString(writer, content);
8971d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
8981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
8991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
900ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    count = xmlTextWriterEndComment(writer);
9011d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
9021d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
9031d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
9041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
9051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
9061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
9071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
9081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
9091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterStartElement:
9101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
9111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @name:  element name
9121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
9131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Start an xml element.
9141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
9151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
9161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
9171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
9181d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterStartElement(xmlTextWriterPtr writer, const xmlChar * name)
9191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
9201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
9211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
9221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlLinkPtr lk;
9231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterStackEntry *p;
9241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
9251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if ((writer == NULL) || (name == NULL) || (*name == '\0'))
9261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
9271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
9281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
9291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    lk = xmlListFront(writer->nodes);
9301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (lk != 0) {
9311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
9321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (p != 0) {
9331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            switch (p->state) {
9341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                case XML_TEXTWRITER_PI:
9351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                case XML_TEXTWRITER_PI_TEXT:
9361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    return -1;
9371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                case XML_TEXTWRITER_NONE:
9381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    break;
939614fdc13b7d073b6732fff5bb2baf16ef2ade18dDaniel Veillard				case XML_TEXTWRITER_ATTRIBUTE:
940614fdc13b7d073b6732fff5bb2baf16ef2ade18dDaniel Veillard					count = xmlTextWriterEndAttribute(writer);
941614fdc13b7d073b6732fff5bb2baf16ef2ade18dDaniel Veillard					if (count < 0)
942614fdc13b7d073b6732fff5bb2baf16ef2ade18dDaniel Veillard						return -1;
943614fdc13b7d073b6732fff5bb2baf16ef2ade18dDaniel Veillard					sum += count;
944614fdc13b7d073b6732fff5bb2baf16ef2ade18dDaniel Veillard					/* fallthrough */
9451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                case XML_TEXTWRITER_NAME:
9461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    count = xmlOutputBufferWriteString(writer->out, ">");
9471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    if (count < 0)
9481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        return -1;
9491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    sum += count;
950ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                    if (writer->indent)
951ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                        count =
952ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                            xmlOutputBufferWriteString(writer->out, "\n");
9531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    p->state = XML_TEXTWRITER_TEXT;
9541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    break;
955ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                default:
956ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                    break;
9571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            }
9581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        }
9591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
9601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
9611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p = (xmlTextWriterStackEntry *)
9621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlMalloc(sizeof(xmlTextWriterStackEntry));
9631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (p == 0) {
964dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
9651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        "xmlTextWriterStartElement : out of memory!\n");
9661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
9671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
9681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
9691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p->name = xmlStrdup(name);
9701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (p->name == 0) {
971dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
9721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        "xmlTextWriterStartElement : out of memory!\n");
9731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlFree(p);
9741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
9751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
9761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p->state = XML_TEXTWRITER_NAME;
9771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
9781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlListPushFront(writer->nodes, p);
9791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
980ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    if (writer->indent) {
981ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        count = xmlTextWriterWriteIndent(writer);
982ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        sum += count;
9832cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard    }
9842cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard
9851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlOutputBufferWriteString(writer->out, "<");
9861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
9871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
9881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
9895841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    count =
9905841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        xmlOutputBufferWriteString(writer->out, (const char *) p->name);
9911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
9921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
9931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
9941d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
9951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
9961d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
9971d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
9981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
9991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterStartElementNS:
10001d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
10011d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @prefix:  namespace prefix or NULL
10021d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @name:  element local name
10031d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @namespaceURI:  namespace URI or NULL
10041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
10051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Start an xml element with namespace support.
10061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
10071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
10081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
10091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
10101d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterStartElementNS(xmlTextWriterPtr writer,
10111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                            const xmlChar * prefix, const xmlChar * name,
10121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                            const xmlChar * namespaceURI)
10131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
10141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
10151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
10161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlChar *buf;
10171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
10181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if ((writer == NULL) || (name == NULL) || (*name == '\0'))
10191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
10201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
102175e389d4e0ccd998d288387051e66a8f0b2af1b0Daniel Veillard    buf = NULL;
10221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (prefix != 0) {
10231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        buf = xmlStrdup(prefix);
10241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        buf = xmlStrcat(buf, BAD_CAST ":");
10251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
10261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    buf = xmlStrcat(buf, name);
10271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
10281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
10291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterStartElement(writer, buf);
10301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlFree(buf);
10311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
10321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
10331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
10341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
10351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (namespaceURI != 0) {
10361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        buf = xmlStrdup(BAD_CAST "xmlns");
10371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (prefix != 0) {
10381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            buf = xmlStrcat(buf, BAD_CAST ":");
10391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            buf = xmlStrcat(buf, prefix);
10401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        }
10411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
10421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlTextWriterWriteAttribute(writer, buf, namespaceURI);
10431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlFree(buf);
10441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
10451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
10461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
10471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
10481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
10491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
10501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
10511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
10521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
10531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterEndElement:
10541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
10551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
10561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * End the current xml element.
10571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
10581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
10591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
10601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
10611d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterEndElement(xmlTextWriterPtr writer)
10621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
10631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
10641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
10651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlLinkPtr lk;
10661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterStackEntry *p;
10671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
10681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL)
10691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
10701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
10711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    lk = xmlListFront(writer->nodes);
10721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (lk == 0)
10731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
10741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
10751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
10761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (p == 0)
10771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
10781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
10791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
10801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    switch (p->state) {
10811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        case XML_TEXTWRITER_ATTRIBUTE:
10821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            count = xmlTextWriterEndAttribute(writer);
10831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (count < 0)
10841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
10851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            sum += count;
10861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            /* fallthrough */
10871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        case XML_TEXTWRITER_NAME:
1088ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard            if (writer->indent) /* next element needs indent */
1089ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                writer->doindent = 1;
10901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            count = xmlOutputBufferWriteString(writer->out, "/>");
10911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (count < 0)
10921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
10931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            sum += count;
10941d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            break;
10951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        case XML_TEXTWRITER_TEXT:
1096ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard            if ((writer->indent) && (writer->doindent)) {
1097ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                count = xmlTextWriterWriteIndent(writer);
1098ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                sum += count;
1099ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                writer->doindent = 1;
1100ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard            } else
1101ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                writer->doindent = 1;
11021d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            count = xmlOutputBufferWriteString(writer->out, "</");
11031d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (count < 0)
11041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
11051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            sum += count;
11061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            count = xmlOutputBufferWriteString(writer->out,
1107ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                                               (const char *) p->name);
11081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (count < 0)
11091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
11101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            sum += count;
11111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            count = xmlOutputBufferWriteString(writer->out, ">");
11121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (count < 0)
11131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
11141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            sum += count;
11151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            break;
11161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        default:
11171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
11181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
11191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
11202cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard    if (writer->indent) {
1121ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        count = xmlOutputBufferWriteString(writer->out, "\n");
1122ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        sum += count;
11232cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard    }
11242cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard
11251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlListPopFront(writer->nodes);
11261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
11271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
11281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
11291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
11301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterFullEndElement:
11311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
11321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
11331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * End the current xml element. Writes an end tag even if the element is empty
11341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
11351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
11361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
11371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
11381d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterFullEndElement(xmlTextWriterPtr writer)
11391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
11401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
11411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
11421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlLinkPtr lk;
11431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterStackEntry *p;
11441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
11451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL)
11461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
11471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
11481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    lk = xmlListFront(writer->nodes);
11491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (lk == 0)
11501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
11511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
11521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
11531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (p == 0)
11541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
11551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
11561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
11571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    switch (p->state) {
11581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        case XML_TEXTWRITER_ATTRIBUTE:
11591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            count = xmlTextWriterEndAttribute(writer);
11601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (count < 0)
11611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
11621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            sum += count;
11631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            /* fallthrough */
11641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        case XML_TEXTWRITER_NAME:
11651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            count = xmlOutputBufferWriteString(writer->out, ">");
11661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (count < 0)
11671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
11681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            sum += count;
11691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            /* fallthrough */
11701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        case XML_TEXTWRITER_TEXT:
11711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            count = xmlOutputBufferWriteString(writer->out, "</");
11721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (count < 0)
11731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
11741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            sum += count;
11751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            count = xmlOutputBufferWriteString(writer->out,
1176ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                                               (const char *) p->name);
11771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (count < 0)
11781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
11791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            sum += count;
11801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            count = xmlOutputBufferWriteString(writer->out, ">");
11811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (count < 0)
11821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
11831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            sum += count;
11841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            break;
11851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        default:
11861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
11871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
11881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
11891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlListPopFront(writer->nodes);
11901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
11911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
11921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
11931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
11941d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteFormatRaw:
11951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
11961d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @format:  format string (see printf)
11971d913863130a17a638db69c2c50f89e5b0d4aae4Daniel Veillard * @...:  extra parameters for the format
11981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
11991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write a formatted raw xml text.
12001d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
12011d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
12021d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
1203ffa3c74933baa45bef5e0d7f15473c38a4c3f9e8Daniel Veillardint XMLCDECL
12041d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteFormatRaw(xmlTextWriterPtr writer, const char *format,
12051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                            ...)
12061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
12071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
12081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_list ap;
12091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
12101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_start(ap, format);
12111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
12121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteVFormatRaw(writer, format, ap);
12131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
12141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_end(ap);
12151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
12161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
12171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
12181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
12191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteVFormatRaw:
12201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
12211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @format:  format string (see printf)
12221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @argptr:  pointer to the first member of the variable argument list.
12231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
12241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write a formatted raw xml text.
12251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
12261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
12271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
12281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
12291d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteVFormatRaw(xmlTextWriterPtr writer, const char *format,
12301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                             va_list argptr)
12311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
12321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
12331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlChar *buf;
12341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
12351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL)
12361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
12371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
12381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    buf = xmlTextWriterVSprintf(format, argptr);
12391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (buf == 0)
12401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return 0;
12411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
12421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteRaw(writer, buf);
12431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
12441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlFree(buf);
12451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
12461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
12471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
12481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
12491e90661bb817402f85103c3b9d3ce6ebab570f38Daniel Veillard * xmlTextWriterWriteRawLen:
12501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
12511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @content:  text string
12521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @len:  length of the text string
12531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
12541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write an xml text.
12551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * TODO: what about entities and special chars??
12561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
12571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
12581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
12591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
12601d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteRawLen(xmlTextWriterPtr writer, const xmlChar * content,
12611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                         int len)
12621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
12631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
12641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
12651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlLinkPtr lk;
12661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterStackEntry *p;
12671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
1268500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (writer == NULL) {
1269dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
1270500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        "xmlTextWriterWriteRawLen : invalid writer!\n");
12711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
1272500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
12731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
1274e43cc574e49cd8173e157d8c31973f709a4cb7ecDaniel Veillard    if ((content == NULL) || (len < 0)) {
1275dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
1276500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        "xmlTextWriterWriteRawLen : invalid content!\n");
1277500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        return -1;
1278500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
12791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
12801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
1281500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    lk = xmlListFront(writer->nodes);
1282500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (lk != 0) {
1283500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1284500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        count = xmlTextWriterHandleStateDependencies(writer, p);
1285500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        if (count < 0)
12861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
1287500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        sum += count;
12881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
12891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
1290500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (writer->indent)
1291500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        writer->doindent = 0;
1292500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
1293500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (content != NULL) {
1294500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        count =
1295500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            xmlOutputBufferWrite(writer->out, len, (const char *) content);
1296500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        if (count < 0)
1297500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            return -1;
1298500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        sum += count;
1299500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
13001d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
13011d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
13021d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
13031d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
13041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
13051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteRaw:
13061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
13071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @content:  text string
13081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
13091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write a raw xml text.
13101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
13111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
13121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
13131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
13141d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteRaw(xmlTextWriterPtr writer, const xmlChar * content)
13151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
13161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return xmlTextWriterWriteRawLen(writer, content, xmlStrlen(content));
13171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
13181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
13191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
13201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteFormatString:
13211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
13221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @format:  format string (see printf)
13231d913863130a17a638db69c2c50f89e5b0d4aae4Daniel Veillard * @...:  extra parameters for the format
13241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
13251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write a formatted xml text.
13261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
13271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
13281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
1329ffa3c74933baa45bef5e0d7f15473c38a4c3f9e8Daniel Veillardint XMLCDECL
13301d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteFormatString(xmlTextWriterPtr writer, const char *format,
13311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                               ...)
13321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
13331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
13341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_list ap;
13351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
1336e43cc574e49cd8173e157d8c31973f709a4cb7ecDaniel Veillard    if ((writer == NULL) || (format == NULL))
1337e43cc574e49cd8173e157d8c31973f709a4cb7ecDaniel Veillard        return -1;
1338e43cc574e49cd8173e157d8c31973f709a4cb7ecDaniel Veillard
13391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_start(ap, format);
13401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
13411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteVFormatString(writer, format, ap);
13421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
13431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_end(ap);
13441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
13451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
13461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
13471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
13481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteVFormatString:
13491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
13501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @format:  format string (see printf)
13511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @argptr:  pointer to the first member of the variable argument list.
13521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
13531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write a formatted xml text.
13541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
13551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
13561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
13571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
13581d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteVFormatString(xmlTextWriterPtr writer,
13591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                const char *format, va_list argptr)
13601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
13611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
13621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlChar *buf;
13631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
1364e43cc574e49cd8173e157d8c31973f709a4cb7ecDaniel Veillard    if ((writer == NULL) || (format == NULL))
13651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
13661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
13671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    buf = xmlTextWriterVSprintf(format, argptr);
13681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (buf == 0)
13691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return 0;
13701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
13711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteString(writer, buf);
13721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
13731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlFree(buf);
13741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
13751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
13761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
13771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
13781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteString:
13791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
13801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @content:  text string
13811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
13821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write an xml text.
13831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
13841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
13851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
13861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
13871d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteString(xmlTextWriterPtr writer, const xmlChar * content)
13881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
1389500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    int count;
13901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
13911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlLinkPtr lk;
13921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterStackEntry *p;
1393500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    xmlChar *buf;
13941d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
1395e43cc574e49cd8173e157d8c31973f709a4cb7ecDaniel Veillard    if ((writer == NULL) || (content == NULL))
13961d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
13971d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
13981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
1399500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    buf = (xmlChar *) content;
1400500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    lk = xmlListFront(writer->nodes);
1401500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (lk != 0) {
1402500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1403500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        if (p != 0) {
1404500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            switch (p->state) {
1405500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                case XML_TEXTWRITER_NAME:
1406500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                case XML_TEXTWRITER_TEXT:
140762040be3602d66ce983dcb22017af4ccc5d8276dDaniel Veillard#if 0
140862040be3602d66ce983dcb22017af4ccc5d8276dDaniel Veillard                    buf = NULL;
140962040be3602d66ce983dcb22017af4ccc5d8276dDaniel Veillard		    xmlOutputBufferWriteEscape(writer->out, content, NULL);
141062040be3602d66ce983dcb22017af4ccc5d8276dDaniel Veillard#endif
1411500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    buf = xmlEncodeSpecialChars(NULL, content);
1412500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    break;
1413500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                case XML_TEXTWRITER_ATTRIBUTE:
1414500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    buf = NULL;
1415500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    xmlAttrSerializeTxtContent(writer->out->buffer, NULL,
1416500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                                               NULL, content);
1417500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    break;
141887640d5f14e7ce8b9844b886c765af0c56de5ca5William M. Brack		default:
141987640d5f14e7ce8b9844b886c765af0c56de5ca5William M. Brack		    break;
1420500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            }
1421500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        }
14221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
14231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
1424500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (buf != NULL) {
1425500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        count = xmlTextWriterWriteRaw(writer, buf);
1426500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        if (count < 0)
1427500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            return -1;
1428500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        sum += count;
1429751c9ec657e784bd941802d722632f19f17f17aeDaniel Veillard
1430500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        if (buf != content)     /* buf was allocated by us, so free it */
1431500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            xmlFree(buf);
1432a9c612c3ee115278fb8dc0cac1b2f2e362f0c052William M. Brack    }
14331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
14341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
14351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
14361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
14371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
14381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlOutputBufferWriteBase64:
14391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @out: the xmlOutputBufferPtr
14401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @data:   binary data
14411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @len:  the number of bytes to encode
14421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
14431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write base64 encoded data to an xmlOutputBuffer.
14441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Adapted from John Walker's base64.c (http://www.fourmilab.ch/).
14451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
14461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
14471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
14481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardstatic int
14491d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlOutputBufferWriteBase64(xmlOutputBufferPtr out, int len,
14501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                           const unsigned char *data)
14511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
14521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    static unsigned char dtable[64] =
145347a318840053e03e60acb437f41e63366f44852cWilliam M. Brack            {'A','B','C','D','E','F','G','H','I','J','K','L','M',
145447a318840053e03e60acb437f41e63366f44852cWilliam M. Brack	     'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
145547a318840053e03e60acb437f41e63366f44852cWilliam M. Brack	     'a','b','c','d','e','f','g','h','i','j','k','l','m',
145647a318840053e03e60acb437f41e63366f44852cWilliam M. Brack	     'n','o','p','q','r','s','t','u','v','w','x','y','z',
145747a318840053e03e60acb437f41e63366f44852cWilliam M. Brack	     '0','1','2','3','4','5','6','7','8','9','+','/'};
145847a318840053e03e60acb437f41e63366f44852cWilliam M. Brack
14591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int i;
14601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int linelen;
14611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
14621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
14631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
1464e43cc574e49cd8173e157d8c31973f709a4cb7ecDaniel Veillard    if ((out == NULL) || (len < 0) || (data == NULL))
1465e43cc574e49cd8173e157d8c31973f709a4cb7ecDaniel Veillard        return(-1);
1466e43cc574e49cd8173e157d8c31973f709a4cb7ecDaniel Veillard
14671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    linelen = 0;
14681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
14691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
14701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    i = 0;
14711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    while (1) {
14721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        unsigned char igroup[3];
14731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        unsigned char ogroup[4];
14741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        int c;
14751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        int n;
14761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
14771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        igroup[0] = igroup[1] = igroup[2] = 0;
14781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        for (n = 0; n < 3 && i < len; n++, i++) {
14791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            c = data[i];
14801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            igroup[n] = (unsigned char) c;
14811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        }
14821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
14831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (n > 0) {
14841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            ogroup[0] = dtable[igroup[0] >> 2];
14851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            ogroup[1] = dtable[((igroup[0] & 3) << 4) | (igroup[1] >> 4)];
14861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            ogroup[2] =
14871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                dtable[((igroup[1] & 0xF) << 2) | (igroup[2] >> 6)];
14881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            ogroup[3] = dtable[igroup[2] & 0x3F];
14891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
14901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (n < 3) {
14911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                ogroup[3] = '=';
14921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                if (n < 2) {
14931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    ogroup[2] = '=';
14941d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                }
14951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            }
14961d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
14971d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (linelen >= B64LINELEN) {
14981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                count = xmlOutputBufferWrite(out, 2, B64CRLF);
14991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                if (count == -1)
15001d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    return -1;
15011d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                sum += count;
15021d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                linelen = 0;
15031d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            }
15041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            count = xmlOutputBufferWrite(out, 4, (const char *) ogroup);
15051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (count == -1)
15061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
15071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            sum += count;
15081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
15091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            linelen += 4;
15101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        }
1511929714b707a2d793cd78b033bfacb56fbaea3e36Daniel Veillard
1512929714b707a2d793cd78b033bfacb56fbaea3e36Daniel Veillard        if (i >= len)
1513929714b707a2d793cd78b033bfacb56fbaea3e36Daniel Veillard            break;
15141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
15151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
15161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
15171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
15181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
15191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
15201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteBase64:
15211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer: the xmlTextWriterPtr
15221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @data:   binary data
15231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @start:  the position within the data of the first byte to encode
15241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @len:  the number of bytes to encode
15251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
15261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write an base64 encoded xml text.
15271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
15281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
15291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
15301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
1531ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel VeillardxmlTextWriterWriteBase64(xmlTextWriterPtr writer, const char *data,
15321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                         int start, int len)
15331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
15341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
15351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
15361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlLinkPtr lk;
15371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterStackEntry *p;
15381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
1539e43cc574e49cd8173e157d8c31973f709a4cb7ecDaniel Veillard    if ((writer == NULL) || (data == NULL) || (start < 0) || (len < 0))
15401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
15411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
15421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
1543500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    lk = xmlListFront(writer->nodes);
1544500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (lk != 0) {
1545500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1546500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        if (p != 0) {
1547500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            count = xmlTextWriterHandleStateDependencies(writer, p);
15481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (count < 0)
15491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
15501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            sum += count;
1551500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        }
15521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
15531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
1554ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    if (writer->indent)
1555ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        writer->doindent = 0;
1556ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
15571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count =
15581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlOutputBufferWriteBase64(writer->out, len,
15591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                   (unsigned char *) data + start);
15601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
15611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
15621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
15631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
15641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
15651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
15661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
15671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
15681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlOutputBufferWriteBinHex:
15691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @out: the xmlOutputBufferPtr
15701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @data:   binary data
15711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @len:  the number of bytes to encode
15721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
15731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write hqx encoded data to an xmlOutputBuffer.
15741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * ::todo
15751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
157647a318840053e03e60acb437f41e63366f44852cWilliam M. Brack * Returns the bytes written (may be 0 because of buffering)
157747a318840053e03e60acb437f41e63366f44852cWilliam M. Brack * or -1 in case of error
15781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
15791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardstatic int
1580ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel VeillardxmlOutputBufferWriteBinHex(xmlOutputBufferPtr out,
1581ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                           int len, const unsigned char *data)
15821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
1583ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    int count;
1584ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    int sum;
158547a318840053e03e60acb437f41e63366f44852cWilliam M. Brack    static char hex[16] =
158647a318840053e03e60acb437f41e63366f44852cWilliam M. Brack    	{'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
1587ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    int i;
1588ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
1589e43cc574e49cd8173e157d8c31973f709a4cb7ecDaniel Veillard    if ((out == NULL) || (data == NULL) || (len < 0)) {
1590ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        return -1;
1591ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    }
1592ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
1593ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    sum = 0;
1594ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    for (i = 0; i < len; i++) {
1595ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        count =
1596ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard            xmlOutputBufferWrite(out, 1,
1597ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                                 (const char *) &hex[data[i] >> 4]);
1598ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        if (count == -1)
1599ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard            return -1;
1600ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        sum += count;
1601ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        count =
1602ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard            xmlOutputBufferWrite(out, 1,
1603ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                                 (const char *) &hex[data[i] & 0xF]);
1604ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        if (count == -1)
1605ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard            return -1;
1606ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        sum += count;
1607ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    }
1608ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
1609ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    return sum;
16101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
16111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
16121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
16131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteBinHex:
16141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer: the xmlTextWriterPtr
16151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @data:   binary data
16161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @start:  the position within the data of the first byte to encode
16171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @len:  the number of bytes to encode
16181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
16191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write a BinHex encoded xml text.
16201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
16211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
16221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
16231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
1624ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel VeillardxmlTextWriterWriteBinHex(xmlTextWriterPtr writer, const char *data,
16251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                         int start, int len)
16261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
16271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
16281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
16291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlLinkPtr lk;
16301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterStackEntry *p;
16311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
1632e43cc574e49cd8173e157d8c31973f709a4cb7ecDaniel Veillard    if ((writer == NULL) || (data == NULL) || (start < 0) || (len < 0))
16331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
16341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
16351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
1636500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    lk = xmlListFront(writer->nodes);
1637500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (lk != 0) {
1638500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1639500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        if (p != 0) {
1640500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            count = xmlTextWriterHandleStateDependencies(writer, p);
16411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (count < 0)
16421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
16431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            sum += count;
1644500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        }
16451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
16461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
1647ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    if (writer->indent)
1648ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        writer->doindent = 0;
1649ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
16501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count =
16511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlOutputBufferWriteBinHex(writer->out, len,
16521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                   (unsigned char *) data + start);
16531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
16541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
16551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
16561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
16571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
16581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
16591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
16601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
16611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterStartAttribute:
16621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
16631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @name:  element name
16641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
16651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Start an xml attribute.
16661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
16671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
16681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
16691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
16701d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterStartAttribute(xmlTextWriterPtr writer, const xmlChar * name)
16711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
16721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
16731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
16741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlLinkPtr lk;
16751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterStackEntry *p;
16761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
16771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if ((writer == NULL) || (name == NULL) || (*name == '\0'))
16781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
16791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
16801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
16811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    lk = xmlListFront(writer->nodes);
16821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (lk == 0)
16831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
16841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
16851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
16861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (p == 0)
16871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
16881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
16891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    switch (p->state) {
16901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        case XML_TEXTWRITER_ATTRIBUTE:
16911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            count = xmlTextWriterEndAttribute(writer);
16921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (count < 0)
16931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
16941d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            sum += count;
16951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            /* fallthrough */
16961d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        case XML_TEXTWRITER_NAME:
16971d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            count = xmlOutputBufferWriteString(writer->out, " ");
16981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (count < 0)
16991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
17001d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            sum += count;
17015841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard            count =
17025841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                xmlOutputBufferWriteString(writer->out,
17035841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                                           (const char *) name);
17041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (count < 0)
17051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
17061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            sum += count;
17071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            count = xmlOutputBufferWriteString(writer->out, "=");
17081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (count < 0)
17091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
17101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            sum += count;
17111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
17121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (count < 0)
17131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
17141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            sum += count;
17151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            p->state = XML_TEXTWRITER_ATTRIBUTE;
17161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            break;
17171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        default:
17181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
17191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
17201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
17211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
17221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
17231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
17241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
17251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterStartAttributeNS:
17261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
17271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @prefix:  namespace prefix or NULL
17281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @name:  element local name
17291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @namespaceURI:  namespace URI or NULL
17301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
17311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Start an xml attribute with namespace support.
17321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
17331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
17341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
17351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
17361d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterStartAttributeNS(xmlTextWriterPtr writer,
17371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                              const xmlChar * prefix, const xmlChar * name,
17381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                              const xmlChar * namespaceURI)
17391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
17401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
17411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
17421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlChar *buf;
17431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterNsStackEntry *p;
17441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
17451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if ((writer == NULL) || (name == NULL) || (*name == '\0'))
17461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
17471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
174875e389d4e0ccd998d288387051e66a8f0b2af1b0Daniel Veillard    buf = NULL;
17491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (prefix != 0) {
17501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        buf = xmlStrdup(prefix);
17511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        buf = xmlStrcat(buf, BAD_CAST ":");
17521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
17531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    buf = xmlStrcat(buf, name);
17541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
17551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
17561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterStartAttribute(writer, buf);
17571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlFree(buf);
17581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
17591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
17601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
17611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
17621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (namespaceURI != 0) {
17631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        buf = xmlStrdup(BAD_CAST "xmlns");
17641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (prefix != 0) {
17651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            buf = xmlStrcat(buf, BAD_CAST ":");
17661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            buf = xmlStrcat(buf, prefix);
17671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        }
17681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
17691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        p = (xmlTextWriterNsStackEntry *)
17701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            xmlMalloc(sizeof(xmlTextWriterNsStackEntry));
17711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (p == 0) {
1772dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard            xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
17731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                            "xmlTextWriterStartAttributeNS : out of memory!\n");
17741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
17751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        }
17761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
17771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        p->prefix = buf;
17781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        p->uri = xmlStrdup(namespaceURI);
17791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (p->uri == 0) {
1780dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard            xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
17811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                            "xmlTextWriterStartAttributeNS : out of memory!\n");
17821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            xmlFree(p);
17831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
17841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        }
17851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        p->elem = xmlListFront(writer->nodes);
17861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
17871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlListPushFront(writer->nsstack, p);
17881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
17891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
17901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
17911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
17921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
17931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
17941d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterEndAttribute:
17951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
17961d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
17971d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * End the current xml element.
17981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
17991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
18001d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
18011d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
18021d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterEndAttribute(xmlTextWriterPtr writer)
18031d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
18041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
18051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
18061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlLinkPtr lk;
18071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterStackEntry *p;
18081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterNsStackEntry *np;
18091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
18101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL)
18111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
18121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
18131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    lk = xmlListFront(writer->nodes);
18141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (lk == 0) {
18151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlListDelete(writer->nsstack);
1816e43cc574e49cd8173e157d8c31973f709a4cb7ecDaniel Veillard	writer->nsstack = NULL;
18171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
18181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
18191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
18201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
18211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (p == 0) {
18221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlListDelete(writer->nsstack);
1823e43cc574e49cd8173e157d8c31973f709a4cb7ecDaniel Veillard	writer->nsstack = NULL;
18241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
18251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
18261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
18271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
18281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    switch (p->state) {
18291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        case XML_TEXTWRITER_ATTRIBUTE:
18301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            p->state = XML_TEXTWRITER_NAME;
18311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
18321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
18331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (count < 0) {
18341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                xmlListDelete(writer->nsstack);
1835e43cc574e49cd8173e157d8c31973f709a4cb7ecDaniel Veillard		writer->nsstack = NULL;
18361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
18371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            }
18381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            sum += count;
18391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
18401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            while (!xmlListEmpty(writer->nsstack)) {
1841bd8fb0adc02f725a1cbf7f45875a8b2426cf6debDaniel Veillard	        xmlChar *namespaceURI = NULL;
1842bd8fb0adc02f725a1cbf7f45875a8b2426cf6debDaniel Veillard		xmlChar *prefix = NULL;
1843bd8fb0adc02f725a1cbf7f45875a8b2426cf6debDaniel Veillard
18441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                lk = xmlListFront(writer->nsstack);
18451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                np = (xmlTextWriterNsStackEntry *) xmlLinkGetData(lk);
1846bd8fb0adc02f725a1cbf7f45875a8b2426cf6debDaniel Veillard
1847bd8fb0adc02f725a1cbf7f45875a8b2426cf6debDaniel Veillard		if (np != 0) {
1848614fdc13b7d073b6732fff5bb2baf16ef2ade18dDaniel Veillard		    namespaceURI = xmlStrdup(np->uri);
1849614fdc13b7d073b6732fff5bb2baf16ef2ade18dDaniel Veillard		    prefix = xmlStrdup(np->prefix);
1850bd8fb0adc02f725a1cbf7f45875a8b2426cf6debDaniel Veillard		}
1851bd8fb0adc02f725a1cbf7f45875a8b2426cf6debDaniel Veillard
1852bd8fb0adc02f725a1cbf7f45875a8b2426cf6debDaniel Veillard		xmlListPopFront(writer->nsstack);
1853bd8fb0adc02f725a1cbf7f45875a8b2426cf6debDaniel Veillard
18541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                if (np != 0) {
18551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    count =
1856bd8fb0adc02f725a1cbf7f45875a8b2426cf6debDaniel Veillard                        xmlTextWriterWriteAttribute(writer, prefix,
1857bd8fb0adc02f725a1cbf7f45875a8b2426cf6debDaniel Veillard                                                    namespaceURI);
1858bd8fb0adc02f725a1cbf7f45875a8b2426cf6debDaniel Veillard		    xmlFree(namespaceURI);
1859bd8fb0adc02f725a1cbf7f45875a8b2426cf6debDaniel Veillard		    xmlFree(prefix);
1860bd8fb0adc02f725a1cbf7f45875a8b2426cf6debDaniel Veillard
18611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    if (count < 0) {
18621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        xmlListDelete(writer->nsstack);
1863e43cc574e49cd8173e157d8c31973f709a4cb7ecDaniel Veillard			writer->nsstack = NULL;
18641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        return -1;
18651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    }
18661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    sum += count;
18671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                }
18681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            }
18691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            break;
18701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
18711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        default:
18721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            xmlListClear(writer->nsstack);
18731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
18741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
18751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
18761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
18771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
18781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
18791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
18801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteFormatAttribute:
18811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
18821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @name:  attribute name
18831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @format:  format string (see printf)
18841d913863130a17a638db69c2c50f89e5b0d4aae4Daniel Veillard * @...:  extra parameters for the format
18851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
18861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write a formatted xml attribute.
18871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
18881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
18891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
1890ffa3c74933baa45bef5e0d7f15473c38a4c3f9e8Daniel Veillardint XMLCDECL
18911d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteFormatAttribute(xmlTextWriterPtr writer,
18921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                  const xmlChar * name, const char *format,
18931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                  ...)
18941d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
18951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
18961d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_list ap;
18971d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
18981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_start(ap, format);
18991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
19001d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteVFormatAttribute(writer, name, format, ap);
19011d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
19021d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_end(ap);
19031d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
19041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
19051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
19061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
19071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteVFormatAttribute:
19081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
19091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @name:  attribute name
19101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @format:  format string (see printf)
19111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @argptr:  pointer to the first member of the variable argument list.
19121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
19131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write a formatted xml attribute.
19141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
19151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
19161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
19171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
19181d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteVFormatAttribute(xmlTextWriterPtr writer,
19191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                   const xmlChar * name,
19201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                   const char *format, va_list argptr)
19211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
19221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
19231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlChar *buf;
19241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
19251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL)
19261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
19271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
19281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    buf = xmlTextWriterVSprintf(format, argptr);
19291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (buf == 0)
19301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return 0;
19311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
19321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteAttribute(writer, name, buf);
19331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
19341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlFree(buf);
19351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
19361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
19371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
19381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
19391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteAttribute:
19401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
19411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @name:  attribute name
19421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @content:  attribute content
19431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
19441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write an xml attribute.
19451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
19461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
19471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
19481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
19491d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteAttribute(xmlTextWriterPtr writer, const xmlChar * name,
19501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                            const xmlChar * content)
19511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
19521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
19531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
19541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
19551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
19561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterStartAttribute(writer, name);
19571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
19581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
19591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
19601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterWriteString(writer, content);
19611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
19621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
19631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
19641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterEndAttribute(writer);
19651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
19661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
19671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
19681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
19691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
19701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
19711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
19721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
19731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteFormatAttributeNS:
19741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
19751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @prefix:  namespace prefix
19761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @name:  attribute local name
19771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @namespaceURI:  namespace URI
19781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @format:  format string (see printf)
19791d913863130a17a638db69c2c50f89e5b0d4aae4Daniel Veillard * @...:  extra parameters for the format
19801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
19811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write a formatted xml attribute.with namespace support
19821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
19831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
19841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
1985ffa3c74933baa45bef5e0d7f15473c38a4c3f9e8Daniel Veillardint XMLCDECL
19861d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteFormatAttributeNS(xmlTextWriterPtr writer,
19871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                    const xmlChar * prefix,
19881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                    const xmlChar * name,
19891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                    const xmlChar * namespaceURI,
19901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                    const char *format, ...)
19911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
19921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
19931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_list ap;
19941d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
19951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_start(ap, format);
19961d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
19971d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteVFormatAttributeNS(writer, prefix, name,
19981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                              namespaceURI, format, ap);
19991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
20001d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_end(ap);
20011d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
20021d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
20031d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
20041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
20051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteVFormatAttributeNS:
20061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
20071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @prefix:  namespace prefix
20081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @name:  attribute local name
20091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @namespaceURI:  namespace URI
20101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @format:  format string (see printf)
20111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @argptr:  pointer to the first member of the variable argument list.
20121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
20131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write a formatted xml attribute.with namespace support
20141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
20151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
20161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
20171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
20181d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteVFormatAttributeNS(xmlTextWriterPtr writer,
20191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                     const xmlChar * prefix,
20201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                     const xmlChar * name,
20211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                     const xmlChar * namespaceURI,
20221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                     const char *format, va_list argptr)
20231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
20241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
20251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlChar *buf;
20261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
20271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL)
20281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
20291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
20301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    buf = xmlTextWriterVSprintf(format, argptr);
20311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (buf == 0)
20321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return 0;
20331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
20341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteAttributeNS(writer, prefix, name, namespaceURI,
20351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                       buf);
20361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
20371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlFree(buf);
20381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
20391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
20401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
20411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
20421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteAttributeNS:
20431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
20441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @prefix:  namespace prefix
20451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @name:  attribute local name
20461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @namespaceURI:  namespace URI
20471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @content:  attribute content
20481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
20491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write an xml attribute.
20501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
20511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
20521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
20531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
20541d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteAttributeNS(xmlTextWriterPtr writer,
20551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                              const xmlChar * prefix, const xmlChar * name,
20561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                              const xmlChar * namespaceURI,
20571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                              const xmlChar * content)
20581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
20591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
20601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
20611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlChar *buf;
20621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
20631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if ((writer == NULL) || (name == NULL) || (*name == '\0'))
20641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
20651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
206675e389d4e0ccd998d288387051e66a8f0b2af1b0Daniel Veillard    buf = NULL;
20671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (prefix != NULL) {
20681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        buf = xmlStrdup(prefix);
20691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        buf = xmlStrcat(buf, BAD_CAST ":");
20701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
20711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    buf = xmlStrcat(buf, name);
20721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
20731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
20741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterWriteAttribute(writer, buf, content);
20751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlFree(buf);
20761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
20771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
20781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
20791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
20801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (namespaceURI != NULL) {
208175e389d4e0ccd998d288387051e66a8f0b2af1b0Daniel Veillard        buf = NULL;
20821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        buf = xmlStrdup(BAD_CAST "xmlns");
20831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (prefix != NULL) {
20841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            buf = xmlStrcat(buf, BAD_CAST ":");
20851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            buf = xmlStrcat(buf, prefix);
20861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        }
20871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlTextWriterWriteAttribute(writer, buf, namespaceURI);
20881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlFree(buf);
20891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
20901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
20911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
20921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
20931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
20941d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
20951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
20961d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
20971d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteFormatElement:
20981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
20991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @name:  element name
21001d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @format:  format string (see printf)
21011d913863130a17a638db69c2c50f89e5b0d4aae4Daniel Veillard * @...:  extra parameters for the format
21021d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
21031d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write a formatted xml element.
21041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
21051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
21061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
2107ffa3c74933baa45bef5e0d7f15473c38a4c3f9e8Daniel Veillardint XMLCDECL
21081d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteFormatElement(xmlTextWriterPtr writer,
21091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                const xmlChar * name, const char *format,
21101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                ...)
21111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
21121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
21131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_list ap;
21141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
21151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_start(ap, format);
21161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
21171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteVFormatElement(writer, name, format, ap);
21181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
21191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_end(ap);
21201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
21211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
21221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
21231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
21241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteVFormatElement:
21251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
21261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @name:  element name
21271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @format:  format string (see printf)
21281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @argptr:  pointer to the first member of the variable argument list.
21291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
21301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write a formatted xml element.
21311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
21321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
21331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
21341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
21351d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteVFormatElement(xmlTextWriterPtr writer,
21361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                 const xmlChar * name, const char *format,
21371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                 va_list argptr)
21381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
21391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
21401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlChar *buf;
21411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
21421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL)
21431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
21441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
21451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    buf = xmlTextWriterVSprintf(format, argptr);
21461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (buf == 0)
21471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return 0;
21481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
21491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteElement(writer, name, buf);
21501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
21511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlFree(buf);
21521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
21531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
21541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
21551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
21561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteElement:
21571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
21581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @name:  element name
21591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @content:  element content
21601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
21611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write an xml element.
21621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
21631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
21641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
21651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
21661d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteElement(xmlTextWriterPtr writer, const xmlChar * name,
21671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                          const xmlChar * content)
21681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
21691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
21701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
21711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
21721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
21731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterStartElement(writer, name);
21741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count == -1)
21751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
21761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
21771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterWriteString(writer, content);
21781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count == -1)
21791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
21801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
21811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterEndElement(writer);
21821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count == -1)
21831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
21841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
21851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
21861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
21871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
21881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
21891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
21901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteFormatElementNS:
21911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
21921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @prefix:  namespace prefix
21931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @name:  element local name
21941d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @namespaceURI:  namespace URI
21951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @format:  format string (see printf)
21961d913863130a17a638db69c2c50f89e5b0d4aae4Daniel Veillard * @...:  extra parameters for the format
21971d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
21981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write a formatted xml element with namespace support.
21991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
22001d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
22011d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
2202ffa3c74933baa45bef5e0d7f15473c38a4c3f9e8Daniel Veillardint XMLCDECL
22031d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteFormatElementNS(xmlTextWriterPtr writer,
22041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                  const xmlChar * prefix,
22051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                  const xmlChar * name,
22061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                  const xmlChar * namespaceURI,
22071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                  const char *format, ...)
22081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
22091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
22101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_list ap;
22111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
22121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_start(ap, format);
22131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
22141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteVFormatElementNS(writer, prefix, name,
22151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                            namespaceURI, format, ap);
22161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
22171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_end(ap);
22181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
22191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
22201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
22211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
22221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteVFormatElementNS:
22231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
22241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @prefix:  namespace prefix
22251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @name:  element local name
22261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @namespaceURI:  namespace URI
22271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @format:  format string (see printf)
22281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @argptr:  pointer to the first member of the variable argument list.
22291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
22301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write a formatted xml element with namespace support.
22311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
22321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
22331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
22341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
22351d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteVFormatElementNS(xmlTextWriterPtr writer,
22361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                   const xmlChar * prefix,
22371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                   const xmlChar * name,
22381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                   const xmlChar * namespaceURI,
22391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                   const char *format, va_list argptr)
22401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
22411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
22421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlChar *buf;
22431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
22441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL)
22451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
22461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
22471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    buf = xmlTextWriterVSprintf(format, argptr);
22481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (buf == 0)
22491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return 0;
22501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
22511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteElementNS(writer, prefix, name, namespaceURI,
22521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                     buf);
22531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
22541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlFree(buf);
22551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
22561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
22571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
22581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
22591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteElementNS:
22601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
22611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @prefix:  namespace prefix
22621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @name:  element local name
22631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @namespaceURI:  namespace URI
22641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @content:  element content
22651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
22661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write an xml element with namespace support.
22671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
22681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
22691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
22701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
22711d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteElementNS(xmlTextWriterPtr writer,
22721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                            const xmlChar * prefix, const xmlChar * name,
22731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                            const xmlChar * namespaceURI,
22741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                            const xmlChar * content)
22751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
22761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
22771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
22781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
22791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if ((writer == NULL) || (name == NULL) || (*name == '\0'))
22801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
22811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
22821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
22831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count =
22841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlTextWriterStartElementNS(writer, prefix, name, namespaceURI);
22851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
22861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
22871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
22881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterWriteString(writer, content);
22891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count == -1)
22901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
22911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
22921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterEndElement(writer);
22931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count == -1)
22941d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
22951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
22961d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
22971d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
22981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
22991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
23001d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
23011d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterStartPI:
23021d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
23031d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @target:  PI target
23041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
23051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Start an xml PI.
23061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
23071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
23081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
23091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
23101d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterStartPI(xmlTextWriterPtr writer, const xmlChar * target)
23111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
23121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
23131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
23141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlLinkPtr lk;
23151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterStackEntry *p;
23161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
23171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if ((writer == NULL) || (target == NULL) || (*target == '\0'))
23181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
23191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
23201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (xmlStrcasecmp(target, (const xmlChar *) "xml") == 0) {
2321dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
23221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        "xmlTextWriterStartPI : target name [Xx][Mm][Ll] is reserved for xml standardization!\n");
23231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
23241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
23251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
23261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
23271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    lk = xmlListFront(writer->nodes);
23281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (lk != 0) {
23291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
23301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (p != 0) {
23311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            switch (p->state) {
23321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                case XML_TEXTWRITER_ATTRIBUTE:
23331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    count = xmlTextWriterEndAttribute(writer);
23341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    if (count < 0)
23351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        return -1;
23361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    sum += count;
23371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    /* fallthrough */
23381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                case XML_TEXTWRITER_NAME:
23391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    count = xmlOutputBufferWriteString(writer->out, ">");
23401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    if (count < 0)
23411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        return -1;
23421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    sum += count;
23431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    p->state = XML_TEXTWRITER_TEXT;
23441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    break;
2345ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                case XML_TEXTWRITER_NONE:
2346ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                case XML_TEXTWRITER_TEXT:
2347ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                case XML_TEXTWRITER_DTD:
2348ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                    break;
23491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                case XML_TEXTWRITER_PI:
23501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                case XML_TEXTWRITER_PI_TEXT:
2351dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard                    xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
23521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                    "xmlTextWriterStartPI : nested PI!\n");
23531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    return -1;
23541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                default:
23551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    return -1;
23561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            }
23571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        }
23581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
23591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
23601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p = (xmlTextWriterStackEntry *)
23611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlMalloc(sizeof(xmlTextWriterStackEntry));
23621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (p == 0) {
2363dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
23641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        "xmlTextWriterStartPI : out of memory!\n");
23651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
23661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
23671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
23681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p->name = xmlStrdup(target);
23691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (p->name == 0) {
2370dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
23711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        "xmlTextWriterStartPI : out of memory!\n");
23721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlFree(p);
23731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
23741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
23751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p->state = XML_TEXTWRITER_PI;
23761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
23771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlListPushFront(writer->nodes, p);
23781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
23791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlOutputBufferWriteString(writer->out, "<?");
23801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
23811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
23821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
23835841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    count =
23845841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        xmlOutputBufferWriteString(writer->out, (const char *) p->name);
23851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
23861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
23871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
23881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
23891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
23901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
23911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
23921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
23931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterEndPI:
23941d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
23951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
23961d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * End the current xml PI.
23971d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
23981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
23991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
24001d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
24011d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterEndPI(xmlTextWriterPtr writer)
24021d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
24031d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
24041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
24051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlLinkPtr lk;
24061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterStackEntry *p;
24071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
24081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL)
24091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
24101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
24111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    lk = xmlListFront(writer->nodes);
24121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (lk == 0)
24131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return 0;
24141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
24151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
24161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (p == 0)
24171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return 0;
24181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
24191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
24201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    switch (p->state) {
24211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        case XML_TEXTWRITER_PI:
24221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        case XML_TEXTWRITER_PI_TEXT:
24231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            count = xmlOutputBufferWriteString(writer->out, "?>");
24241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (count < 0)
24251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
24261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            sum += count;
24271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            break;
24281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        default:
24291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
24301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
24311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
24321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlListPopFront(writer->nodes);
24331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
24341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
24351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
24361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
24371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteFormatPI:
24381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
24391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @target:  PI target
24401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @format:  format string (see printf)
24411d913863130a17a638db69c2c50f89e5b0d4aae4Daniel Veillard * @...:  extra parameters for the format
24421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
24431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write a formatted PI.
24441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
24451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
24461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
2447ffa3c74933baa45bef5e0d7f15473c38a4c3f9e8Daniel Veillardint XMLCDECL
24481d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteFormatPI(xmlTextWriterPtr writer, const xmlChar * target,
24491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                           const char *format, ...)
24501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
24511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
24521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_list ap;
24531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
24541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_start(ap, format);
24551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
24561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteVFormatPI(writer, target, format, ap);
24571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
24581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_end(ap);
24591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
24601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
24611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
24621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
24631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteVFormatPI:
24641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
24651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @target:  PI target
24661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @format:  format string (see printf)
24675841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @argptr:  pointer to the first member of the variable argument list.
24681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
24691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write a formatted xml PI.
24701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
24711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
24721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
24731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
24741d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteVFormatPI(xmlTextWriterPtr writer,
24751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                            const xmlChar * target, const char *format,
24761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                            va_list argptr)
24771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
24781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
24791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlChar *buf;
24801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
24811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL)
24821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
24831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
24841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    buf = xmlTextWriterVSprintf(format, argptr);
24851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (buf == 0)
24861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return 0;
24871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
24881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWritePI(writer, target, buf);
24891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
24901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlFree(buf);
24911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
24921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
24931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
24941d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
24951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWritePI:
24961d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
24971d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @target:  PI target
24981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @content:  PI content
24991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
25001d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write an xml PI.
25011d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
25021d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
25031d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
25041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
25051d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWritePI(xmlTextWriterPtr writer, const xmlChar * target,
25061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                     const xmlChar * content)
25071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
25081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
25091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
25101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
25111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
25121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterStartPI(writer, target);
25131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count == -1)
25141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
25151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
25161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (content != 0) {
25171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlTextWriterWriteString(writer, content);
25181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count == -1)
25191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
25201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
25211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
25221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterEndPI(writer);
25231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count == -1)
25241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
25251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
25261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
25271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
25281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
25291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
25301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
25311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterStartCDATA:
25321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
25331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
25341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Start an xml CDATA section.
25351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
25361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
25371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
25381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
25391d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterStartCDATA(xmlTextWriterPtr writer)
25401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
25411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
25421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
25431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlLinkPtr lk;
25441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterStackEntry *p;
25451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
25461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL)
25471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
25481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
25491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
25501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    lk = xmlListFront(writer->nodes);
25511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (lk != 0) {
25521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
25531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (p != 0) {
25541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            switch (p->state) {
25551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                case XML_TEXTWRITER_NONE:
25561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                case XML_TEXTWRITER_PI:
25571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                case XML_TEXTWRITER_PI_TEXT:
25581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    break;
25591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                case XML_TEXTWRITER_ATTRIBUTE:
25601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    count = xmlTextWriterEndAttribute(writer);
25611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    if (count < 0)
25621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        return -1;
25631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    sum += count;
25641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    /* fallthrough */
25651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                case XML_TEXTWRITER_NAME:
25661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    count = xmlOutputBufferWriteString(writer->out, ">");
25671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    if (count < 0)
25681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        return -1;
25691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    sum += count;
25701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    p->state = XML_TEXTWRITER_TEXT;
25711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    break;
25721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                case XML_TEXTWRITER_CDATA:
2573dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard                    xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
25741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                    "xmlTextWriterStartCDATA : CDATA not allowed in this context!\n");
25751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    return -1;
25761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                default:
25771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                    return -1;
25781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            }
25791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        }
25801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
25811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
25821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p = (xmlTextWriterStackEntry *)
25831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlMalloc(sizeof(xmlTextWriterStackEntry));
25841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (p == 0) {
2585dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
25861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        "xmlTextWriterStartCDATA : out of memory!\n");
25871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
25881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
25891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
259075e389d4e0ccd998d288387051e66a8f0b2af1b0Daniel Veillard    p->name = NULL;
25911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p->state = XML_TEXTWRITER_CDATA;
25921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
25931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlListPushFront(writer->nodes, p);
25941d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
25951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlOutputBufferWriteString(writer->out, "<![CDATA[");
25961d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
25971d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
25981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
25991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
26001d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
26011d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
26021d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
26031d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
26041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterEndCDATA:
26051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
26061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
26071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * End an xml CDATA section.
26081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
26091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
26101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
26111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
26121d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterEndCDATA(xmlTextWriterPtr writer)
26131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
26141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
26151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
26161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlLinkPtr lk;
26171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterStackEntry *p;
26181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
26191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL)
26201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
26211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
26221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    lk = xmlListFront(writer->nodes);
26231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (lk == 0)
26241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
26251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
26261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
26271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (p == 0)
26281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
26291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
26301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
26311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    switch (p->state) {
26321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        case XML_TEXTWRITER_CDATA:
26331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            count = xmlOutputBufferWriteString(writer->out, "]]>");
26341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (count < 0)
26351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
26361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            sum += count;
26371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            break;
26381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        default:
26391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
26401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
26411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
26421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlListPopFront(writer->nodes);
26431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
26441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
26451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
26461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
26471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteFormatCDATA:
26481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
26491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @format:  format string (see printf)
26501d913863130a17a638db69c2c50f89e5b0d4aae4Daniel Veillard * @...:  extra parameters for the format
26511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
26521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write a formatted xml CDATA.
26531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
26541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
26551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
2656ffa3c74933baa45bef5e0d7f15473c38a4c3f9e8Daniel Veillardint XMLCDECL
26571d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteFormatCDATA(xmlTextWriterPtr writer, const char *format,
26581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                              ...)
26591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
26601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
26611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_list ap;
26621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
26631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_start(ap, format);
26641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
26651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteVFormatCDATA(writer, format, ap);
26661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
26671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_end(ap);
26681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
26691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
26701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
26711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
26721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteVFormatCDATA:
26731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
26741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @format:  format string (see printf)
26755841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @argptr:  pointer to the first member of the variable argument list.
26761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
26771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write a formatted xml CDATA.
26781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
26791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
26801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
26811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
26821d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteVFormatCDATA(xmlTextWriterPtr writer, const char *format,
26831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                               va_list argptr)
26841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
26851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
26861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlChar *buf;
26871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
26881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL)
26891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
26901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
26911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    buf = xmlTextWriterVSprintf(format, argptr);
26921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (buf == 0)
26931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return 0;
26941d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
26951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteCDATA(writer, buf);
26961d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
26971d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlFree(buf);
26981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
26991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
27001d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
27011d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
27021d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteCDATA:
27031d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
27041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @content:  CDATA content
27051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
27061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write an xml CDATA.
27071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
27081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
27091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
27101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
27111d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteCDATA(xmlTextWriterPtr writer, const xmlChar * content)
27121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
27131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
27141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
27151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
27161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
27171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterStartCDATA(writer);
27181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count == -1)
27191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
27201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
27211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (content != 0) {
27221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlTextWriterWriteString(writer, content);
27231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count == -1)
27241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
27251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
27261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
27271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterEndCDATA(writer);
27281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count == -1)
27291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
27301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
27311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
27321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
27331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
27341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
27351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
27361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterStartDTD:
27371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
27381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @name:  the name of the DTD
27391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @pubid:  the public identifier, which is an alternative to the system identifier
27401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @sysid:  the system identifier, which is the URI of the DTD
27411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
27421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Start an xml DTD.
27431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
27441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
27451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
27461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
27471d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterStartDTD(xmlTextWriterPtr writer,
27481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                      const xmlChar * name,
27491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                      const xmlChar * pubid, const xmlChar * sysid)
27501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
27511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
27521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
27531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlLinkPtr lk;
27541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterStackEntry *p;
27551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
27561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL || name == NULL || *name == '\0')
27571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
27581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
27591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
27601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    lk = xmlListFront(writer->nodes);
2761ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    if ((lk != NULL) && (xmlLinkGetData(lk) != NULL)) {
2762dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
27631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        "xmlTextWriterStartDTD : DTD allowed only in prolog!\n");
27641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
27651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
27661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
27671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p = (xmlTextWriterStackEntry *)
27681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlMalloc(sizeof(xmlTextWriterStackEntry));
27691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (p == 0) {
2770dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
27711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        "xmlTextWriterStartDTD : out of memory!\n");
27721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
27731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
27741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
27751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p->name = xmlStrdup(name);
27761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (p->name == 0) {
2777dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
27781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        "xmlTextWriterStartDTD : out of memory!\n");
27791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlFree(p);
27801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
27811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
27821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p->state = XML_TEXTWRITER_DTD;
27831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
27841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlListPushFront(writer->nodes, p);
27851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
27861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlOutputBufferWriteString(writer->out, "<!DOCTYPE ");
27871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
27881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
27891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
27901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlOutputBufferWriteString(writer->out, (const char *) name);
27911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
27921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
27931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
27941d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
27951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (pubid != 0) {
27961d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (sysid == 0) {
2797dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard            xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
27981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                            "xmlTextWriterStartDTD : system identifier needed!\n");
27991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
28001d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        }
28011d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
2802500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        if (writer->indent)
2803500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            count = xmlOutputBufferWrite(writer->out, 1, "\n");
2804500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        else
2805500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            count = xmlOutputBufferWrite(writer->out, 1, " ");
2806500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        if (count < 0)
2807500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            return -1;
2808500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        sum += count;
2809500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
2810500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        count = xmlOutputBufferWriteString(writer->out, "PUBLIC ");
2811500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        if (count < 0)
2812500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            return -1;
2813500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        sum += count;
2814500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
2815500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
28161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
28171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
28181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
28191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
28205841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        count =
28215841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard            xmlOutputBufferWriteString(writer->out, (const char *) pubid);
28221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
28231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
28241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
28251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
2826500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
28271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
28281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
28291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
28301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
28311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
28321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (sysid != 0) {
28331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (pubid == 0) {
2834500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            if (writer->indent)
2835500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                count = xmlOutputBufferWrite(writer->out, 1, "\n");
2836500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            else
2837500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                count = xmlOutputBufferWrite(writer->out, 1, " ");
2838500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            if (count < 0)
2839500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                return -1;
2840500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            sum += count;
2841500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            count = xmlOutputBufferWriteString(writer->out, "SYSTEM ");
2842500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            if (count < 0)
2843500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                return -1;
2844500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            sum += count;
2845500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        } else if (writer->indent) {
2846500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            count = xmlOutputBufferWriteString(writer->out, "\n       ");
28471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (count < 0)
28481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
28491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            sum += count;
28501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        }
28511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
2852500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
28531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
28541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
28551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
28561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
28575841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        count =
28585841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard            xmlOutputBufferWriteString(writer->out, (const char *) sysid);
28591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
28601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
28611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
28621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
2863500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
28641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
28651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
28661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
28671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
28681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
28691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
28701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
28711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
28721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
28731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterEndDTD:
28741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
28751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
28761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * End an xml DTD.
28771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
28781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
28791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
28801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
28811d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterEndDTD(xmlTextWriterPtr writer)
28821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
2883500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    int loop;
28841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
28851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
28861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlLinkPtr lk;
28871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterStackEntry *p;
28881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
28891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL)
28901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
28911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
28921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
2893500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    loop = 1;
2894500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    while (loop) {
2895500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        lk = xmlListFront(writer->nodes);
2896500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        if (lk == NULL)
2897500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            break;
2898500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
2899500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        if (p == 0)
2900500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            break;
2901500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        switch (p->state) {
2902500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD_TEXT:
2903500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                count = xmlOutputBufferWriteString(writer->out, "]");
2904500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                if (count < 0)
2905500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    return -1;
2906500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                sum += count;
2907500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                /* fallthrough */
2908500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD:
2909500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                count = xmlOutputBufferWriteString(writer->out, ">");
29101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
2911500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                if (writer->indent) {
2912500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    if (count < 0)
2913500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        return -1;
2914500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    sum += count;
2915500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    count = xmlOutputBufferWriteString(writer->out, "\n");
2916500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                }
29171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
2918500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                xmlListPopFront(writer->nodes);
2919500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                break;
2920500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD_ELEM:
2921500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD_ELEM_TEXT:
2922500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                count = xmlTextWriterEndDTDElement(writer);
2923500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                break;
2924500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD_ATTL:
2925500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD_ATTL_TEXT:
2926500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                count = xmlTextWriterEndDTDAttlist(writer);
2927500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                break;
2928500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD_ENTY:
2929500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD_PENT:
2930500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD_ENTY_TEXT:
2931500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                count = xmlTextWriterEndDTDEntity(writer);
2932500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                break;
2933500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_COMMENT:
2934500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                count = xmlTextWriterEndComment(writer);
2935500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                break;
2936500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            default:
2937500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                loop = 0;
2938500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                continue;
2939500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        }
2940500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
2941500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        if (count < 0)
29421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
2943500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        sum += count;
29441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
29451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
29461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
29471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
29481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
29491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
29501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteFormatDTD:
29511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
29521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @name:  the name of the DTD
29531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @pubid:  the public identifier, which is an alternative to the system identifier
29541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @sysid:  the system identifier, which is the URI of the DTD
29551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @format:  format string (see printf)
29561d913863130a17a638db69c2c50f89e5b0d4aae4Daniel Veillard * @...:  extra parameters for the format
29571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
29581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write a DTD with a formatted markup declarations part.
29591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
29601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
29611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
2962ffa3c74933baa45bef5e0d7f15473c38a4c3f9e8Daniel Veillardint XMLCDECL
29631d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteFormatDTD(xmlTextWriterPtr writer,
29641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                            const xmlChar * name,
29651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                            const xmlChar * pubid,
29661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                            const xmlChar * sysid, const char *format, ...)
29671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
29681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
29691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_list ap;
29701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
29711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_start(ap, format);
29721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
29731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteVFormatDTD(writer, name, pubid, sysid, format,
29741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                      ap);
29751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
29761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_end(ap);
29771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
29781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
29791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
29801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
29811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteVFormatDTD:
29821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
29831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @name:  the name of the DTD
29841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @pubid:  the public identifier, which is an alternative to the system identifier
29851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @sysid:  the system identifier, which is the URI of the DTD
29861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @format:  format string (see printf)
29875841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @argptr:  pointer to the first member of the variable argument list.
29881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
29891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write a DTD with a formatted markup declarations part.
29901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
29911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
29921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
29931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
29941d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteVFormatDTD(xmlTextWriterPtr writer,
29951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                             const xmlChar * name,
29961d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                             const xmlChar * pubid,
29971d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                             const xmlChar * sysid,
29981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                             const char *format, va_list argptr)
29991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
30001d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
30011d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlChar *buf;
30021d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
30031d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL)
30041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
30051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
30061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    buf = xmlTextWriterVSprintf(format, argptr);
30071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (buf == 0)
30081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return 0;
30091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
30101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteDTD(writer, name, pubid, sysid, buf);
30111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
30121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlFree(buf);
30131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
30141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
30151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
30161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
30171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteDTD:
30181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
30191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @name:  the name of the DTD
30201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @pubid:  the public identifier, which is an alternative to the system identifier
30211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @sysid:  the system identifier, which is the URI of the DTD
3022b1d531659b2bee47492ca1c319180116eaaf566eWilliam M. Brack * @subset:  string content of the DTD
30231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
30241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write a DTD.
30251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
30261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
30271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
30281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
30291d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteDTD(xmlTextWriterPtr writer,
30301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                      const xmlChar * name,
30311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                      const xmlChar * pubid,
30321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                      const xmlChar * sysid, const xmlChar * subset)
30331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
30341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
30351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
30361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
30371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
30381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterStartDTD(writer, name, pubid, sysid);
30391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count == -1)
30401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
30411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
30421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (subset != 0) {
30431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlTextWriterWriteString(writer, subset);
30441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count == -1)
30451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
30461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
30471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
30481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterEndDTD(writer);
30491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count == -1)
30501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
30511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
30521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
30531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
30541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
30551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
30565841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard/**
30575841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * xmlTextWriterStartDTDElement:
30585841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @writer:  the xmlTextWriterPtr
30595841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @name:  the name of the DTD element
30605841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
30615841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Start an xml DTD element.
30625841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
30635841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
30645841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard */
30651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
30661d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterStartDTDElement(xmlTextWriterPtr writer, const xmlChar * name)
30671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
30681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
30691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
30701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlLinkPtr lk;
30711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterStackEntry *p;
30721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
30731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL || name == NULL || *name == '\0')
30741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
30751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
30761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
30771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    lk = xmlListFront(writer->nodes);
30781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (lk == 0) {
30791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
30801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
30811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
30821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3083500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (p != 0) {
3084500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        switch (p->state) {
3085500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD:
3086500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                count = xmlOutputBufferWriteString(writer->out, " [");
3087500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                if (count < 0)
3088500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    return -1;
3089500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                sum += count;
3090500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                if (writer->indent) {
3091500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    count = xmlOutputBufferWriteString(writer->out, "\n");
3092500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    if (count < 0)
3093500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        return -1;
3094500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    sum += count;
3095500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                }
3096500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                p->state = XML_TEXTWRITER_DTD_TEXT;
3097500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                /* fallthrough */
3098500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD_TEXT:
3099500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_NONE:
3100500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                break;
3101500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            default:
31021d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
3103500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        }
31041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
31051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
31061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p = (xmlTextWriterStackEntry *)
31071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlMalloc(sizeof(xmlTextWriterStackEntry));
31081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (p == 0) {
3109dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
31101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        "xmlTextWriterStartDTDElement : out of memory!\n");
31111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
31121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
31131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
31141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p->name = xmlStrdup(name);
31151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (p->name == 0) {
3116dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
31171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        "xmlTextWriterStartDTDElement : out of memory!\n");
31181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlFree(p);
31191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
31201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
31211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p->state = XML_TEXTWRITER_DTD_ELEM;
31221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
31231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlListPushFront(writer->nodes, p);
31241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
3125500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (writer->indent) {
3126500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        count = xmlTextWriterWriteIndent(writer);
3127500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        if (count < 0)
3128500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            return -1;
3129500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        sum += count;
3130500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
3131500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
31321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlOutputBufferWriteString(writer->out, "<!ELEMENT ");
31331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
31341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
31351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
31361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlOutputBufferWriteString(writer->out, (const char *) name);
31371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
31381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
31391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
31401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
31411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
31421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
31431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
31445841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard/**
3145500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * xmlTextWriterEndDTDElement:
3146500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * @writer:  the xmlTextWriterPtr
3147500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard *
3148500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * End an xml DTD element.
3149500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard *
3150500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3151500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard */
3152500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillardint
3153500a1de533e2ea03f452844f537bb247b7e43af2Daniel VeillardxmlTextWriterEndDTDElement(xmlTextWriterPtr writer)
3154500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard{
3155500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    int count;
3156500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    int sum;
3157500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    xmlLinkPtr lk;
3158500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    xmlTextWriterStackEntry *p;
3159500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3160500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (writer == NULL)
3161500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        return -1;
3162500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3163500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    sum = 0;
3164500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    lk = xmlListFront(writer->nodes);
3165500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (lk == 0)
3166500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        return -1;
3167500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3168500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3169500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (p == 0)
3170500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        return -1;
3171500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3172500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    switch (p->state) {
3173500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        case XML_TEXTWRITER_DTD_ELEM:
3174500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        case XML_TEXTWRITER_DTD_ELEM_TEXT:
3175500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            count = xmlOutputBufferWriteString(writer->out, ">");
3176500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            if (count < 0)
3177500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                return -1;
3178500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            sum += count;
3179500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            break;
3180500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        default:
3181500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            return -1;
3182500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
3183500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3184500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (writer->indent) {
3185500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        count = xmlOutputBufferWriteString(writer->out, "\n");
3186500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        if (count < 0)
3187500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            return -1;
3188500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        sum += count;
3189500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
3190500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3191500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    xmlListPopFront(writer->nodes);
3192500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    return sum;
3193500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard}
3194500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3195500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard/**
31965841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * xmlTextWriterWriteFormatDTDElement:
31975841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @writer:  the xmlTextWriterPtr
31985841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @name:  the name of the DTD element
31995841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @format:  format string (see printf)
32001d913863130a17a638db69c2c50f89e5b0d4aae4Daniel Veillard * @...:  extra parameters for the format
32015841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
32025841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Write a formatted DTD element.
32035841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
32045841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
32055841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard */
3206ffa3c74933baa45bef5e0d7f15473c38a4c3f9e8Daniel Veillardint XMLCDECL
32071d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteFormatDTDElement(xmlTextWriterPtr writer,
32081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                   const xmlChar * name,
32091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                   const char *format, ...)
32101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
32111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
32121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_list ap;
32131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
32141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_start(ap, format);
32151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
32161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteVFormatDTDElement(writer, name, format, ap);
32171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
32181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_end(ap);
32191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
32201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
32211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
32225841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard/**
32235841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * xmlTextWriterWriteVFormatDTDElement:
32245841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @writer:  the xmlTextWriterPtr
32255841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @name:  the name of the DTD element
32265841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @format:  format string (see printf)
32275841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @argptr:  pointer to the first member of the variable argument list.
32285841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
32295841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Write a formatted DTD element.
32305841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
32315841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
32325841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard */
32331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
32341d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteVFormatDTDElement(xmlTextWriterPtr writer,
32351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                    const xmlChar * name,
32361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                    const char *format, va_list argptr)
32371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
32381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
32391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlChar *buf;
32401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
32411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL)
32421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
32431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
32441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    buf = xmlTextWriterVSprintf(format, argptr);
32451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (buf == 0)
32461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return 0;
32471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
32481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteDTDElement(writer, name, buf);
32491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
32501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlFree(buf);
32511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
32521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
32531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
32545841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard/**
32555841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * xmlTextWriterWriteDTDElement:
32565841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @writer:  the xmlTextWriterPtr
32575841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @name:  the name of the DTD element
32585841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @content:  content of the element
32595841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
32605841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Write a DTD element.
32615841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
32625841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
32635841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard */
32641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
32651d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteDTDElement(xmlTextWriterPtr writer,
32661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                             const xmlChar * name, const xmlChar * content)
32671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
32681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
32691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
32701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
32711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (content == NULL)
32721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
32731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
32741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
32751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterStartDTDElement(writer, name);
32761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count == -1)
32771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
32781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
32791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
32801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterWriteString(writer, content);
32811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count == -1)
32821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
32831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
32841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
32851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterEndDTDElement(writer);
32861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count == -1)
32871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
32881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
32891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
32901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
32911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
32921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
32935841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard/**
32945841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * xmlTextWriterStartDTDAttlist:
32955841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @writer:  the xmlTextWriterPtr
32965841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @name:  the name of the DTD ATTLIST
32975841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
32985841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Start an xml DTD ATTLIST.
32995841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
33005841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
33015841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard */
33021d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
33031d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterStartDTDAttlist(xmlTextWriterPtr writer, const xmlChar * name)
33041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
33051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
33061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
33071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlLinkPtr lk;
33081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterStackEntry *p;
33091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
33101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL || name == NULL || *name == '\0')
33111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
33121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
33131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
33141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    lk = xmlListFront(writer->nodes);
33151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (lk == 0) {
33161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
33171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
33181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
33191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3320500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (p != 0) {
3321500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        switch (p->state) {
3322500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD:
3323500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                count = xmlOutputBufferWriteString(writer->out, " [");
3324500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                if (count < 0)
3325500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    return -1;
3326500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                sum += count;
3327500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                if (writer->indent) {
3328500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    count = xmlOutputBufferWriteString(writer->out, "\n");
3329500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    if (count < 0)
3330500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        return -1;
3331500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    sum += count;
3332500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                }
3333500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                p->state = XML_TEXTWRITER_DTD_TEXT;
3334500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                /* fallthrough */
3335500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD_TEXT:
3336500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_NONE:
3337500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                break;
3338500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            default:
33391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
3340500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        }
33411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
33421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
33431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p = (xmlTextWriterStackEntry *)
33441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlMalloc(sizeof(xmlTextWriterStackEntry));
33451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (p == 0) {
3346dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
33471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        "xmlTextWriterStartDTDAttlist : out of memory!\n");
33481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
33491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
33501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
33511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p->name = xmlStrdup(name);
33521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (p->name == 0) {
3353dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
33541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        "xmlTextWriterStartDTDAttlist : out of memory!\n");
33551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlFree(p);
33561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
33571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
33581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p->state = XML_TEXTWRITER_DTD_ATTL;
33591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
33601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlListPushFront(writer->nodes, p);
33611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
3362500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (writer->indent) {
3363500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        count = xmlTextWriterWriteIndent(writer);
3364500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        if (count < 0)
3365500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            return -1;
3366500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        sum += count;
3367500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
3368500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
33691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlOutputBufferWriteString(writer->out, "<!ATTLIST ");
33701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
33711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
33721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
3373ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    count = xmlOutputBufferWriteString(writer->out, (const char *) name);
33741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
33751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
33761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
33771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
33781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
33791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
33801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
33815841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard/**
3382500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * xmlTextWriterEndDTDAttlist:
3383500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * @writer:  the xmlTextWriterPtr
3384500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard *
3385500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * End an xml DTD attribute list.
3386500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard *
3387500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3388500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard */
3389500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillardint
3390500a1de533e2ea03f452844f537bb247b7e43af2Daniel VeillardxmlTextWriterEndDTDAttlist(xmlTextWriterPtr writer)
3391500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard{
3392500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    int count;
3393500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    int sum;
3394500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    xmlLinkPtr lk;
3395500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    xmlTextWriterStackEntry *p;
3396500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3397500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (writer == NULL)
3398500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        return -1;
3399500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3400500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    sum = 0;
3401500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    lk = xmlListFront(writer->nodes);
3402500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (lk == 0)
3403500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        return -1;
3404500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3405500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3406500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (p == 0)
3407500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        return -1;
3408500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3409500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    switch (p->state) {
3410500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        case XML_TEXTWRITER_DTD_ATTL:
3411500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        case XML_TEXTWRITER_DTD_ATTL_TEXT:
3412500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            count = xmlOutputBufferWriteString(writer->out, ">");
3413500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            if (count < 0)
3414500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                return -1;
3415500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            sum += count;
3416500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            break;
3417500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        default:
3418500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            return -1;
3419500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
3420500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3421500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (writer->indent) {
3422500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        count = xmlOutputBufferWriteString(writer->out, "\n");
3423500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        if (count < 0)
3424500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            return -1;
3425500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        sum += count;
3426500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
3427500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3428500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    xmlListPopFront(writer->nodes);
3429500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    return sum;
3430500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard}
3431500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3432500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard/**
34335841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * xmlTextWriterWriteFormatDTDAttlist:
34345841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @writer:  the xmlTextWriterPtr
34355841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @name:  the name of the DTD ATTLIST
34365841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @format:  format string (see printf)
34371d913863130a17a638db69c2c50f89e5b0d4aae4Daniel Veillard * @...:  extra parameters for the format
34385841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
34395841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Write a formatted DTD ATTLIST.
34405841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
34415841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
34425841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard */
3443ffa3c74933baa45bef5e0d7f15473c38a4c3f9e8Daniel Veillardint XMLCDECL
34441d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteFormatDTDAttlist(xmlTextWriterPtr writer,
34451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                   const xmlChar * name,
34461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                   const char *format, ...)
34471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
34481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
34491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_list ap;
34501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
34511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_start(ap, format);
34521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
34531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteVFormatDTDAttlist(writer, name, format, ap);
34541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
34551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_end(ap);
34561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
34571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
34581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
34595841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard/**
34605841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * xmlTextWriterWriteVFormatDTDAttlist:
34615841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @writer:  the xmlTextWriterPtr
34625841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @name:  the name of the DTD ATTLIST
34635841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @format:  format string (see printf)
34645841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @argptr:  pointer to the first member of the variable argument list.
34655841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
34665841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Write a formatted DTD ATTLIST.
34675841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
34685841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
34695841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard */
34701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
34711d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteVFormatDTDAttlist(xmlTextWriterPtr writer,
34721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                    const xmlChar * name,
34731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                    const char *format, va_list argptr)
34741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
34751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
34761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlChar *buf;
34771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
34781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL)
34791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
34801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
34811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    buf = xmlTextWriterVSprintf(format, argptr);
34821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (buf == 0)
34831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return 0;
34841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
34851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteDTDAttlist(writer, name, buf);
34861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
34871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlFree(buf);
34881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
34891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
34901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
34915841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard/**
34925841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * xmlTextWriterWriteDTDAttlist:
34935841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @writer:  the xmlTextWriterPtr
34945841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @name:  the name of the DTD ATTLIST
34955841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @content:  content of the ATTLIST
34965841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
34975841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Write a DTD ATTLIST.
34985841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
34995841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
35005841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard */
35011d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
35021d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteDTDAttlist(xmlTextWriterPtr writer,
35031d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                             const xmlChar * name, const xmlChar * content)
35041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
35051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
35061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
35071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
35081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (content == NULL)
35091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
35101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
35111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
35121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterStartDTDAttlist(writer, name);
35131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count == -1)
35141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
35151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
35161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
35171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterWriteString(writer, content);
35181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count == -1)
35191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
35201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
35211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
35221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterEndDTDAttlist(writer);
35231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count == -1)
35241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
35251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
35261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
35271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
35281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
35291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
35305841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard/**
35315841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * xmlTextWriterStartDTDEntity:
35325841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @writer:  the xmlTextWriterPtr
35335841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @pe:  TRUE if this is a parameter entity, FALSE if not
35345841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @name:  the name of the DTD ATTLIST
35355841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
35365841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Start an xml DTD ATTLIST.
35375841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
35385841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
35395841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard */
35401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
35411d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterStartDTDEntity(xmlTextWriterPtr writer,
35421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                            int pe, const xmlChar * name)
35431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
35441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
35451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
35461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlLinkPtr lk;
35471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterStackEntry *p;
35481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
35491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL || name == NULL || *name == '\0')
35501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
35511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
35521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
35531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    lk = xmlListFront(writer->nodes);
3554500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (lk != 0) {
35551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
3556500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3557500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        if (p != 0) {
3558500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            switch (p->state) {
3559500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                case XML_TEXTWRITER_DTD:
3560500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    count = xmlOutputBufferWriteString(writer->out, " [");
3561500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    if (count < 0)
3562500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        return -1;
3563500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    sum += count;
3564500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    if (writer->indent) {
3565500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        count =
3566500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                            xmlOutputBufferWriteString(writer->out, "\n");
3567500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        if (count < 0)
3568500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                            return -1;
3569500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        sum += count;
3570500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    }
3571500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    p->state = XML_TEXTWRITER_DTD_TEXT;
3572500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    /* fallthrough */
3573500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                case XML_TEXTWRITER_DTD_TEXT:
3574500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                case XML_TEXTWRITER_NONE:
3575500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    break;
3576500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                default:
3577500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    return -1;
3578500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            }
3579500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        }
35801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
35811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
35821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p = (xmlTextWriterStackEntry *)
35831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlMalloc(sizeof(xmlTextWriterStackEntry));
35841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (p == 0) {
3585dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
35861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        "xmlTextWriterStartDTDElement : out of memory!\n");
35871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
35881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
35891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
35901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p->name = xmlStrdup(name);
35911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (p->name == 0) {
3592dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
35931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        "xmlTextWriterStartDTDElement : out of memory!\n");
35941d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlFree(p);
35951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
35961d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
3597500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3598500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (pe != 0)
3599500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        p->state = XML_TEXTWRITER_DTD_PENT;
3600500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    else
3601500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        p->state = XML_TEXTWRITER_DTD_ENTY;
36021d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
36031d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlListPushFront(writer->nodes, p);
36041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
3605500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (writer->indent) {
3606500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        count = xmlTextWriterWriteIndent(writer);
3607500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        if (count < 0)
3608500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            return -1;
3609500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        sum += count;
3610500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
3611500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
36121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlOutputBufferWriteString(writer->out, "<!ENTITY ");
36131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
36141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
36151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
36161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
36171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (pe != 0) {
3618500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        count = xmlOutputBufferWriteString(writer->out, "% ");
36191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
36201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
36211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
36221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
36231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
3624ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    count = xmlOutputBufferWriteString(writer->out, (const char *) name);
36251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
36261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
36271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
36281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
36291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
36301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
36311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
36325841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard/**
3633500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * xmlTextWriterEndDTDEntity:
3634500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * @writer:  the xmlTextWriterPtr
3635500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard *
3636500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * End an xml DTD entity.
3637500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard *
3638500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3639500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard */
3640500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillardint
3641500a1de533e2ea03f452844f537bb247b7e43af2Daniel VeillardxmlTextWriterEndDTDEntity(xmlTextWriterPtr writer)
3642500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard{
3643500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    int count;
3644500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    int sum;
3645500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    xmlLinkPtr lk;
3646500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    xmlTextWriterStackEntry *p;
3647500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3648500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (writer == NULL)
3649500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        return -1;
3650500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3651500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    sum = 0;
3652500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    lk = xmlListFront(writer->nodes);
3653500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (lk == 0)
3654500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        return -1;
3655500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3656500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3657500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (p == 0)
3658500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        return -1;
3659500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3660500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    switch (p->state) {
3661500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        case XML_TEXTWRITER_DTD_ENTY_TEXT:
3662500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
3663500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            if (count < 0)
3664500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                return -1;
3665500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            sum += count;
3666500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        case XML_TEXTWRITER_DTD_ENTY:
3667500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        case XML_TEXTWRITER_DTD_PENT:
3668500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            count = xmlOutputBufferWriteString(writer->out, ">");
3669500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            if (count < 0)
3670500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                return -1;
3671500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            sum += count;
3672500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            break;
3673500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        default:
3674500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            return -1;
3675500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
3676500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3677500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (writer->indent) {
3678500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        count = xmlOutputBufferWriteString(writer->out, "\n");
3679500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        if (count < 0)
3680500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            return -1;
3681500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        sum += count;
3682500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
3683500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3684500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    xmlListPopFront(writer->nodes);
3685500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    return sum;
3686500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard}
3687500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3688500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard/**
36895841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * xmlTextWriterWriteFormatDTDInternalEntity:
36905841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @writer:  the xmlTextWriterPtr
36915841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @pe:  TRUE if this is a parameter entity, FALSE if not
36925841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @name:  the name of the DTD entity
36935841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @format:  format string (see printf)
36941d913863130a17a638db69c2c50f89e5b0d4aae4Daniel Veillard * @...:  extra parameters for the format
36955841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
36965841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Write a formatted DTD internal entity.
36975841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
36985841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
36995841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard */
3700ffa3c74933baa45bef5e0d7f15473c38a4c3f9e8Daniel Veillardint XMLCDECL
37011d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteFormatDTDInternalEntity(xmlTextWriterPtr writer,
37021d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                          int pe,
37031d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                          const xmlChar * name,
37041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                          const char *format, ...)
37051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
37061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
37071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_list ap;
37081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
37091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_start(ap, format);
37101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
37111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteVFormatDTDInternalEntity(writer, pe, name,
37121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                                    format, ap);
37131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
37141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    va_end(ap);
37151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
37161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
37171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
37185841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard/**
37195841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * xmlTextWriterWriteVFormatDTDInternalEntity:
37205841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @writer:  the xmlTextWriterPtr
37215841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @pe:  TRUE if this is a parameter entity, FALSE if not
37225841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @name:  the name of the DTD entity
37235841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @format:  format string (see printf)
37245841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @argptr:  pointer to the first member of the variable argument list.
37255841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
37265841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Write a formatted DTD internal entity.
37275841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
37285841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
37295841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard */
37301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
37311d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteVFormatDTDInternalEntity(xmlTextWriterPtr writer,
37321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                           int pe,
37331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                           const xmlChar * name,
37341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                           const char *format,
37351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                           va_list argptr)
37361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
37371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
37381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlChar *buf;
37391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
37401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL)
37411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
37421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
37431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    buf = xmlTextWriterVSprintf(format, argptr);
37441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (buf == 0)
37451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return 0;
37461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
37471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlTextWriterWriteDTDInternalEntity(writer, pe, name, buf);
37481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
37491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlFree(buf);
37501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
37511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
37521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
37535841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard/**
37545841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * xmlTextWriterWriteDTDEntity:
37555841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @writer:  the xmlTextWriterPtr
37565841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @pe:  TRUE if this is a parameter entity, FALSE if not
37575841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @name:  the name of the DTD entity
37585841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @pubid:  the public identifier, which is an alternative to the system identifier
37595841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @sysid:  the system identifier, which is the URI of the DTD
37605841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @ndataid:  the xml notation name.
37615841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @content:  content of the entity
37625841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
37635841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Write a DTD entity.
37645841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
37655841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
37665841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard */
37671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
37681d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteDTDEntity(xmlTextWriterPtr writer,
37691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                            int pe,
37701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                            const xmlChar * name,
37711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                            const xmlChar * pubid,
37721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                            const xmlChar * sysid,
37731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                            const xmlChar * ndataid,
37741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                            const xmlChar * content)
37751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
3776500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if ((content == NULL) && (pubid == NULL) && (sysid == NULL))
37771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
37781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if ((pe != 0) && (ndataid != NULL))
37791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
37801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
3781500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if ((pubid == NULL) && (sysid == NULL))
37821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return xmlTextWriterWriteDTDInternalEntity(writer, pe, name,
37831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                                   content);
37841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
37851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return xmlTextWriterWriteDTDExternalEntity(writer, pe, name, pubid,
37861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                               sysid, ndataid);
37871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
37881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
37895841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard/**
37905841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * xmlTextWriterWriteDTDInternalEntity:
37915841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @writer:  the xmlTextWriterPtr
37925841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @pe:  TRUE if this is a parameter entity, FALSE if not
37935841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @name:  the name of the DTD entity
37945841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @content:  content of the entity
37955841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
37965841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Write a DTD internal entity.
37975841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
37985841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
37995841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard */
38001d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
38011d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteDTDInternalEntity(xmlTextWriterPtr writer,
38021d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                    int pe,
38031d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                    const xmlChar * name,
38041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                    const xmlChar * content)
38051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
38061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
38071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
38081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
38091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if ((name == NULL) || (*name == '\0') || (content == NULL))
38101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
38111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
38121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
38131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterStartDTDEntity(writer, pe, name);
38141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count == -1)
38151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
38161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
38171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
38181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterWriteString(writer, content);
38191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count == -1)
38201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
38211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
38221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
38231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterEndDTDEntity(writer);
38241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count == -1)
38251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
38261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
38271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
38281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
38291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
38301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
38315841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard/**
38325841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * xmlTextWriterWriteDTDExternalEntity:
38335841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @writer:  the xmlTextWriterPtr
38345841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @pe:  TRUE if this is a parameter entity, FALSE if not
38355841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @name:  the name of the DTD entity
38365841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @pubid:  the public identifier, which is an alternative to the system identifier
38375841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @sysid:  the system identifier, which is the URI of the DTD
38385841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @ndataid:  the xml notation name.
38395841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
3840500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * Write a DTD external entity. The entity must have been started with xmlTextWriterStartDTDEntity
38415841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
38425841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
38435841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard */
38441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
38451d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteDTDExternalEntity(xmlTextWriterPtr writer,
38461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                    int pe,
38471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                    const xmlChar * name,
38481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                    const xmlChar * pubid,
38491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                    const xmlChar * sysid,
38501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                                    const xmlChar * ndataid)
38511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
38521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
38531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
38541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
3855500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (((pubid == NULL) && (sysid == NULL)))
38561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
38571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if ((pe != 0) && (ndataid != NULL))
38581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
38591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
38601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
38611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlTextWriterStartDTDEntity(writer, pe, name);
38621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count == -1)
38631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
38641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
38651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
3866500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    count =
3867500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        xmlTextWriterWriteDTDExternalEntityContents(writer, pubid, sysid,
3868500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                                                    ndataid);
3869500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (count < 0)
3870500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        return -1;
3871500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    sum += count;
3872500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3873500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    count = xmlTextWriterEndDTDEntity(writer);
3874500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (count == -1)
3875500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        return -1;
3876500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    sum += count;
3877500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3878500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    return sum;
3879500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard}
3880500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3881500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard/**
3882500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * xmlTextWriterWriteDTDExternalEntityContents:
3883500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * @writer:  the xmlTextWriterPtr
3884500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * @pubid:  the public identifier, which is an alternative to the system identifier
3885500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * @sysid:  the system identifier, which is the URI of the DTD
3886500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * @ndataid:  the xml notation name.
3887500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard *
3888500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * Write the contents of a DTD external entity.
3889500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard *
3890500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3891500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard */
3892500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillardint
3893500a1de533e2ea03f452844f537bb247b7e43af2Daniel VeillardxmlTextWriterWriteDTDExternalEntityContents(xmlTextWriterPtr writer,
3894500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                                            const xmlChar * pubid,
3895500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                                            const xmlChar * sysid,
3896500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                                            const xmlChar * ndataid)
3897500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard{
3898500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    int count;
3899500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    int sum;
3900500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    xmlLinkPtr lk;
3901500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    xmlTextWriterStackEntry *p;
3902500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3903500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (writer == NULL) {
3904dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
3905500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        "xmlTextWriterWriteDTDExternalEntityContents: xmlTextWriterPtr invalid!\n");
3906500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        return -1;
3907500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
3908500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3909500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    sum = 0;
3910500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    lk = xmlListFront(writer->nodes);
3911500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (lk == 0) {
3912dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
3913500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        "xmlTextWriterWriteDTDExternalEntityContents: you must call xmlTextWriterStartDTDEntity before the call to this function!\n");
3914500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        return -1;
3915500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
3916500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3917500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3918500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (p == 0)
3919500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        return -1;
3920500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
3921500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    switch (p->state) {
3922500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        case XML_TEXTWRITER_DTD_ENTY:
3923500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            break;
3924500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        case XML_TEXTWRITER_DTD_PENT:
3925500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            if (ndataid != NULL) {
3926dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard                xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
3927500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                                "xmlTextWriterWriteDTDExternalEntityContents: notation not allowed with parameter entities!\n");
3928500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                return -1;
3929500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            }
3930500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            break;
3931500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        default:
3932dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard            xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
3933500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                            "xmlTextWriterWriteDTDExternalEntityContents: you must call xmlTextWriterStartDTDEntity before the call to this function!\n");
3934500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            return -1;
3935500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
3936500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
39371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (pubid != 0) {
39381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (sysid == 0) {
3939dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard            xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
3940500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                            "xmlTextWriterWriteDTDExternalEntityContents: system identifier needed!\n");
39411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
39421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        }
39431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
39441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlOutputBufferWriteString(writer->out, " PUBLIC ");
39451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
39461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
39471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
39481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
39491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
39501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
39511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
39521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
39531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
39545841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        count =
39555841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard            xmlOutputBufferWriteString(writer->out, (const char *) pubid);
39561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
39571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
39581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
39591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
39601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
39611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
39621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
39631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
39641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
39651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
39661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (sysid != 0) {
39671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (pubid == 0) {
39681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            count = xmlOutputBufferWriteString(writer->out, " SYSTEM");
39691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (count < 0)
39701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
39711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            sum += count;
39721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        }
39731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
39741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlOutputBufferWriteString(writer->out, " ");
39751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
39761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
39771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
39781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
39791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
39801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
39811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
39821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
39831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
39845841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        count =
39855841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard            xmlOutputBufferWriteString(writer->out, (const char *) sysid);
39861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
39871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
39881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
39891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
39901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
39911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
39921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
39931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
39941d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
39951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
39961d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (ndataid != NULL) {
39971d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlOutputBufferWriteString(writer->out, " NDATA ");
39981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
39991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
40001d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
40011d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
40025841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        count =
40035841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard            xmlOutputBufferWriteString(writer->out,
40045841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                                       (const char *) ndataid);
40051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
40061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
40071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
40081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
40091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
40101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
40111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
40121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
40135841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard/**
40145841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * xmlTextWriterWriteDTDNotation:
40155841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @writer:  the xmlTextWriterPtr
40165841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @name:  the name of the xml notation
40175841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @pubid:  the public identifier, which is an alternative to the system identifier
40185841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @sysid:  the system identifier, which is the URI of the DTD
40195841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
40205841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Write a DTD entity.
40215841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
40225841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
40235841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard */
40241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
40251d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteDTDNotation(xmlTextWriterPtr writer,
40261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                              const xmlChar * name,
40271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                              const xmlChar * pubid, const xmlChar * sysid)
40281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
40291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
40301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int sum;
40311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlLinkPtr lk;
40321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterStackEntry *p;
40331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
40341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL || name == NULL || *name == '\0')
40351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
40361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
40371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum = 0;
40381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    lk = xmlListFront(writer->nodes);
40391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (lk == 0) {
40401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
40411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
40421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
40431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
4044500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (p != 0) {
4045500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        switch (p->state) {
4046500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD:
4047500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                count = xmlOutputBufferWriteString(writer->out, " [");
4048500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                if (count < 0)
4049500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    return -1;
4050500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                sum += count;
4051500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                if (writer->indent) {
4052500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    count = xmlOutputBufferWriteString(writer->out, "\n");
4053500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    if (count < 0)
4054500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                        return -1;
4055500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                    sum += count;
4056500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                }
4057500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                p->state = XML_TEXTWRITER_DTD_TEXT;
4058500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                /* fallthrough */
4059500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD_TEXT:
4060500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                break;
4061500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            default:
40621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
4063500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        }
4064500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
4065500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
4066500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (writer->indent) {
4067500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        count = xmlTextWriterWriteIndent(writer);
4068500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        if (count < 0)
40691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
4070500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        sum += count;
40711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
40721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
40731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlOutputBufferWriteString(writer->out, "<!NOTATION ");
40741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
40751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
40761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
40771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlOutputBufferWriteString(writer->out, (const char *) name);
40781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
40791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
40801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
40811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
40821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (pubid != 0) {
40831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlOutputBufferWriteString(writer->out, " PUBLIC ");
40841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
40851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
40861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
40871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
40881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
40891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
40901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
40915841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        count =
40925841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard            xmlOutputBufferWriteString(writer->out, (const char *) pubid);
40931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
40941d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
40951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
40961d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
40971d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
40981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
40991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
41001d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
41011d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
41021d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (sysid != 0) {
41031d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (pubid == 0) {
41041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            count = xmlOutputBufferWriteString(writer->out, " SYSTEM");
41051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            if (count < 0)
41061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                return -1;
41071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            sum += count;
41081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        }
41091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlOutputBufferWriteString(writer->out, " ");
41101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
41111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
41121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
41131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
41141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
41151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
41161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
41175841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        count =
41185841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard            xmlOutputBufferWriteString(writer->out, (const char *) sysid);
41191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
41201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
41211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
41221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
41231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (count < 0)
41241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return -1;
41251d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        sum += count;
41261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
41271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
41281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    count = xmlOutputBufferWriteString(writer->out, ">");
41291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (count < 0)
41301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
41311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    sum += count;
41321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
41331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return sum;
41341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
41351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
41361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
41371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterFlush:
41381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @writer:  the xmlTextWriterPtr
41391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
41401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Flush the output buffer.
41411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
41421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
41431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
41441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardint
41451d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterFlush(xmlTextWriterPtr writer)
41461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
41471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
41481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
41491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer == NULL)
41501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
41511d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
41521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (writer->out == NULL)
41531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = 0;
41541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    else
41551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        count = xmlOutputBufferFlush(writer->out);
41561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
41571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return count;
41581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
41591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
41601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
41611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * misc
41621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
41631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
41641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
41651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlFreeTextWriterStackEntry:
41661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @lk:  the xmlLinkPtr
41671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
41681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Free callback for the xmlList.
41691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
41701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardstatic void
41711d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlFreeTextWriterStackEntry(xmlLinkPtr lk)
41721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
41731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterStackEntry *p;
41741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
41751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
41761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (p == 0)
41771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return;
41781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
41791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (p->name != 0)
41801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlFree(p->name);
41811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlFree(p);
41821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
41831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
41841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
41851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlCmpTextWriterStackEntry:
41861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @data0:  the first data
41871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @data1:  the second data
41881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
41891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Compare callback for the xmlList.
41901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
41911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns -1, 0, 1
41921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
41931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardstatic int
41941d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlCmpTextWriterStackEntry(const void *data0, const void *data1)
41951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
41961d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterStackEntry *p0;
41971d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterStackEntry *p1;
41981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
41991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (data0 == data1)
42001d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return 0;
42011d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
42021d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (data0 == 0)
42031d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
42041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
42051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (data1 == 0)
42061d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return 1;
42071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
42081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p0 = (xmlTextWriterStackEntry *) data0;
42091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p1 = (xmlTextWriterStackEntry *) data1;
42101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
42111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return xmlStrcmp(p0->name, p1->name);
42121d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
42131d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
42141d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
42151d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * misc
42161d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
42171d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
42181d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
42191d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlFreeTextWriterNsStackEntry:
42201d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @lk:  the xmlLinkPtr
42211d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
42221d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Free callback for the xmlList.
42231d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
42241d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardstatic void
42251d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlFreeTextWriterNsStackEntry(xmlLinkPtr lk)
42261d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
42271d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterNsStackEntry *p;
42281d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
42291d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p = (xmlTextWriterNsStackEntry *) xmlLinkGetData(lk);
42301d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (p == 0)
42311d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return;
42321d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
42331d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (p->prefix != 0)
42341d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlFree(p->prefix);
42351d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (p->uri != 0)
42361d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlFree(p->uri);
42371d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
42381d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlFree(p);
42391d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
42401d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
42411d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
42421d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlCmpTextWriterNsStackEntry:
42431d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @data0:  the first data
42441d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @data1:  the second data
42451d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
42461d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Compare callback for the xmlList.
42471d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
42481d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns -1, 0, 1
42491d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
42501d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardstatic int
42511d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlCmpTextWriterNsStackEntry(const void *data0, const void *data1)
42521d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
42531d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterNsStackEntry *p0;
42541d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlTextWriterNsStackEntry *p1;
42551d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int rc;
42561d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
42571d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (data0 == data1)
42581d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return 0;
42591d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
42601d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (data0 == 0)
42611d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return -1;
42621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
42631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (data1 == 0)
42641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return 1;
42651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
42661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p0 = (xmlTextWriterNsStackEntry *) data0;
42671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    p1 = (xmlTextWriterNsStackEntry *) data1;
42681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
42691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    rc = xmlStrcmp(p0->prefix, p1->prefix);
42701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
42711d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (rc == 0)
42721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        rc = p0->elem == p1->elem;
42731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
42741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return rc;
42751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
42761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
42771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
42781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterWriteMemCallback:
42791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @context:  the xmlBufferPtr
42801d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @str:  the data to write
42811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @len:  the length of the data
42821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
42831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Write callback for the xmlOutputBuffer with target xmlBuffer
42841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
42851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns -1, 0, 1
42861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
42871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardstatic int
42881d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterWriteMemCallback(void *context, const xmlChar * str, int len)
42891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
42901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlBufferPtr buf = (xmlBufferPtr) context;
42911d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
42921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlBufferAdd(buf, str, len);
42931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
42941d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return len;
42951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
42961d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
42971d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
42981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterCloseMemCallback:
42991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @context:  the xmlBufferPtr
43001d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
43011d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Close callback for the xmlOutputBuffer with target xmlBuffer
43021d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
43031d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns -1, 0, 1
43041d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
43051d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardstatic int
43061d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterCloseMemCallback(void *context ATTRIBUTE_UNUSED)
43071d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
43081d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return 0;
43091d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
43101d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
43111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard/**
43125841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * xmlTextWriterWriteDocCallback:
43135841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @context:  the xmlBufferPtr
43145841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @str:  the data to write
43155841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @len:  the length of the data
43165841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
43175841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Write callback for the xmlOutputBuffer with target xmlBuffer
43185841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
43195841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Returns -1, 0, 1
43205841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard */
43215841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillardstatic int
43225841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel VeillardxmlTextWriterWriteDocCallback(void *context, const xmlChar * str, int len)
43235841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard{
43245841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) context;
43255841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    int rc;
43265841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
43271d913863130a17a638db69c2c50f89e5b0d4aae4Daniel Veillard    if ((rc = xmlParseChunk(ctxt, (const char *) str, len, 0)) != 0) {
4328dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsgInt(NULL, XML_ERR_INTERNAL_ERROR,
43295841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                        "xmlTextWriterWriteDocCallback : XML error %d !\n",
43305841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                        rc);
43315841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        return -1;
43325841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    }
43335841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
43345841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    return len;
43355841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard}
43365841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
43375841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard/**
43385841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * xmlTextWriterCloseDocCallback:
43395841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @context:  the xmlBufferPtr
43405841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
43415841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Close callback for the xmlOutputBuffer with target xmlBuffer
43425841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
43435841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * Returns -1, 0, 1
43445841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard */
43455841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillardstatic int
43465841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel VeillardxmlTextWriterCloseDocCallback(void *context)
43475841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard{
43485841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) context;
43495841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    int rc;
43505841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
43515841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    if ((rc = xmlParseChunk(ctxt, NULL, 0, 1)) != 0) {
4352dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsgInt(NULL, XML_ERR_INTERNAL_ERROR,
43535841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                        "xmlTextWriterWriteDocCallback : XML error %d !\n",
43545841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                        rc);
43555841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        return -1;
43565841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    }
43575841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
43585841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    return 0;
43595841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard}
43605841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
43615841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard/**
43621d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * xmlTextWriterVSprintf:
43631d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @format:  see printf
43641d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * @argptr:  pointer to the first member of the variable argument list.
43651d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
43661d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Utility function for formatted output
43671d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard *
43681d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard * Returns a new xmlChar buffer with the data or NULL on error. This buffer must be freed.
43691d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard */
43701d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillardstatic xmlChar *
43711d211e227372e5ed75a69fbad5f50d185d0af936Daniel VeillardxmlTextWriterVSprintf(const char *format, va_list argptr)
43721d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard{
43731d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int size;
43741d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    int count;
43751d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    xmlChar *buf;
43761d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
43771d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    size = BUFSIZ;
43781d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    buf = (xmlChar *) xmlMalloc(size);
43791d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    if (buf == NULL) {
4380dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard        xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
43811d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                        "xmlTextWriterVSprintf : out of memory!\n");
43821d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        return NULL;
43831d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
43841d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
43851d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    while (((count = vsnprintf((char *) buf, size, format, argptr)) < 0)
43861d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard           || (count == size - 1) || (count == size) || (count > size)) {
43871d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        xmlFree(buf);
43881d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        size += BUFSIZ;
43891d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        buf = (xmlChar *) xmlMalloc(size);
43901d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        if (buf == NULL) {
4391dd6d300896cfeacbacf7c5bceb5bec2f36790efeDaniel Veillard            xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
43921d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard                            "xmlTextWriterVSprintf : out of memory!\n");
43931d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard            return NULL;
43941d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard        }
43951d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    }
43961d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
43971d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard    return buf;
43981d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard}
43991d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard
44005841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard/**
44015841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * xmlTextWriterStartDocumentCallback:
44025841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * @ctx: the user data (XML parser context)
44035841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard *
44045841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard * called at the start of document processing.
44055841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard */
44065841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillardstatic void
44075841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel VeillardxmlTextWriterStartDocumentCallback(void *ctx)
44085841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard{
44095841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
44105841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    xmlDocPtr doc;
44115841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
44125841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    if (ctxt->html) {
44135841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard#ifdef LIBXML_HTML_ENABLED
44145841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        if (ctxt->myDoc == NULL)
44155841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard            ctxt->myDoc = htmlNewDocNoDtD(NULL, NULL);
44165841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        if (ctxt->myDoc == NULL) {
44175841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard            if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
44185841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                ctxt->sax->error(ctxt->userData,
44195841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                                 "SAX.startDocument(): out of memory\n");
44205841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard            ctxt->errNo = XML_ERR_NO_MEMORY;
44215841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard            ctxt->instate = XML_PARSER_EOF;
44225841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard            ctxt->disableSAX = 1;
44235841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard            return;
44245841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        }
44255841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard#else
4426d0cf7f6eea7331cc398c232d7879e4239d989e14Daniel Veillard        xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
44275841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                        "libxml2 built without HTML support\n");
44285841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        ctxt->errNo = XML_ERR_INTERNAL_ERROR;
44295841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        ctxt->instate = XML_PARSER_EOF;
44305841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        ctxt->disableSAX = 1;
44315841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        return;
44325841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard#endif
44335841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    } else {
44345841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        doc = ctxt->myDoc;
44355841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        if (doc == NULL)
44365841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard            doc = ctxt->myDoc = xmlNewDoc(ctxt->version);
44375841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        if (doc != NULL) {
44385841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard            if (doc->children == NULL) {
44395841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                if (ctxt->encoding != NULL)
44405841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                    doc->encoding = xmlStrdup(ctxt->encoding);
44415841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                else
44425841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                    doc->encoding = NULL;
44435841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                doc->standalone = ctxt->standalone;
44445841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard            }
44455841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        } else {
44465841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard            if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
44475841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                ctxt->sax->error(ctxt->userData,
44485841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                                 "SAX.startDocument(): out of memory\n");
44495841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard            ctxt->errNo = XML_ERR_NO_MEMORY;
44505841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard            ctxt->instate = XML_PARSER_EOF;
44515841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard            ctxt->disableSAX = 1;
44525841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard            return;
44535841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        }
44545841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    }
44555841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    if ((ctxt->myDoc != NULL) && (ctxt->myDoc->URL == NULL) &&
44565841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        (ctxt->input != NULL) && (ctxt->input->filename != NULL)) {
44575841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        ctxt->myDoc->URL =
44585841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard            xmlCanonicPath((const xmlChar *) ctxt->input->filename);
44595841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard        if (ctxt->myDoc->URL == NULL)
44605841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard            ctxt->myDoc->URL =
44615841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard                xmlStrdup((const xmlChar *) ctxt->input->filename);
44625841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard    }
44635841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard}
44645841f0e0a44fdfaf6cee6511fbb71d5a76e3ff23Daniel Veillard
44652cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard/**
44662cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard * xmlTextWriterSetIndent:
44672cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard * @writer:  the xmlTextWriterPtr
44682cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard * @indent:  do indentation?
44692cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard *
44702cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard * Set indentation output. indent = 0 do not indentation. indent > 0 do indentation.
44712cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard *
44722cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard * Returns -1 on error or 0 otherwise.
44732cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard */
44742cca446b86a77022d5b847b106544aede7207dbcDaniel Veillardint
4475ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel VeillardxmlTextWriterSetIndent(xmlTextWriterPtr writer, int indent)
44762cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard{
4477e43cc574e49cd8173e157d8c31973f709a4cb7ecDaniel Veillard    if ((writer == NULL) || (indent < 0))
4478ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        return -1;
44792cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard
4480ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    writer->indent = indent;
4481ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    writer->doindent = 1;
44822cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard
4483ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    return 0;
44842cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard}
44852cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard
44862cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard/**
44872cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard * xmlTextWriterSetIndentString:
44882cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard * @writer:  the xmlTextWriterPtr
44892cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard * @str:  the xmlChar string
44902cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard *
44912cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard * Set string indentation.
44922cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard *
44932cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard * Returns -1 on error or 0 otherwise.
44942cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard */
44952cca446b86a77022d5b847b106544aede7207dbcDaniel Veillardint
4496ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel VeillardxmlTextWriterSetIndentString(xmlTextWriterPtr writer, const xmlChar * str)
44972cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard{
4498e43cc574e49cd8173e157d8c31973f709a4cb7ecDaniel Veillard    if ((writer == NULL) || (!str))
4499ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        return -1;
45002cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard
4501ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    if (writer->ichar != NULL)
4502ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        xmlFree(writer->ichar);
4503ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    writer->ichar = xmlStrdup(str);
4504ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
4505ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    if (!writer->ichar)
4506ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        return -1;
4507ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    else
4508ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        return 0;
45092cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard}
45102cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard
45112cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard/**
45122cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard * xmlTextWriterWriteIndent:
45132cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard * @writer:  the xmlTextWriterPtr
45142cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard *
45152cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard * Write indent string.
45162cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard *
45172cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard * Returns -1 on error or the number of strings written.
4518ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard */
45192cca446b86a77022d5b847b106544aede7207dbcDaniel Veillardstatic int
4520ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel VeillardxmlTextWriterWriteIndent(xmlTextWriterPtr writer)
4521ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard{
4522ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    int lksize;
4523ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    int i;
4524ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    int ret;
4525ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
4526ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    lksize = xmlListSize(writer->nodes);
4527ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    if (lksize < 1)
4528ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        return (-1);            /* list is empty */
4529ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    for (i = 0; i < (lksize - 1); i++) {
4530ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        ret = xmlOutputBufferWriteString(writer->out,
4531ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard                                         (const char *) writer->ichar);
4532ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard        if (ret == -1)
4533ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard            return (-1);
4534ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    }
4535ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard
4536ab69f366d0a9178749f2f0a888f6167605bf78f2Daniel Veillard    return (lksize - 1);
45372cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard}
45382cca446b86a77022d5b847b106544aede7207dbcDaniel Veillard
4539500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard/**
4540500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * xmlTextWriterHandleStateDependencies:
4541500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * @writer:  the xmlTextWriterPtr
4542500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * @p:  the xmlTextWriterStackEntry
4543500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard *
4544500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * Write state dependent strings.
4545500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard *
4546500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard * Returns -1 on error or the number of characters written.
4547500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard */
4548500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillardstatic int
4549500a1de533e2ea03f452844f537bb247b7e43af2Daniel VeillardxmlTextWriterHandleStateDependencies(xmlTextWriterPtr writer,
4550500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                                     xmlTextWriterStackEntry * p)
4551500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard{
4552500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    int count;
4553500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    int sum;
4554500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    char extra[3];
4555500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
4556500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (writer == NULL)
4557500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        return -1;
4558500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
4559500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (p == NULL)
4560500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        return 0;
4561500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
4562500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    sum = 0;
4563500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    extra[0] = extra[1] = extra[2] = '\0';
4564500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (p != 0) {
4565500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        sum = 0;
4566500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        switch (p->state) {
4567500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_NAME:
4568500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                extra[0] = '>';
4569500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                p->state = XML_TEXTWRITER_TEXT;
4570500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                break;
4571500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_PI:
4572500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                extra[0] = ' ';
4573500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                p->state = XML_TEXTWRITER_PI_TEXT;
4574500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                break;
4575500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD:
4576500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                extra[0] = ' ';
4577500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                extra[1] = '[';
4578500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                p->state = XML_TEXTWRITER_DTD_TEXT;
4579500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                break;
4580500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD_ELEM:
4581500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                extra[0] = ' ';
4582500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                p->state = XML_TEXTWRITER_DTD_ELEM_TEXT;
4583500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                break;
4584500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD_ATTL:
4585500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                extra[0] = ' ';
4586500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                p->state = XML_TEXTWRITER_DTD_ATTL_TEXT;
4587500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                break;
4588500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD_ENTY:
4589500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            case XML_TEXTWRITER_DTD_PENT:
4590500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                extra[0] = ' ';
4591500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                extra[1] = writer->qchar;
4592500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                p->state = XML_TEXTWRITER_DTD_ENTY_TEXT;
4593500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                break;
4594500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            default:
4595500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard                break;
4596500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        }
4597500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
4598500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
4599500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    if (*extra != '\0') {
4600500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        count = xmlOutputBufferWriteString(writer->out, extra);
4601500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        if (count < 0)
4602500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard            return -1;
4603500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard        sum += count;
4604500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    }
4605500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
4606500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard    return sum;
4607500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard}
4608500a1de533e2ea03f452844f537bb247b7e43af2Daniel Veillard
46095d4644ef6e38479a648615eca758c5e962a141d5Daniel Veillard#define bottom_xmlwriter
46105d4644ef6e38479a648615eca758c5e962a141d5Daniel Veillard#include "elfgcchack.h"
46111d211e227372e5ed75a69fbad5f50d185d0af936Daniel Veillard#endif
4612