3 * xmlwriter.c: XML text writer implementation
5 * For license and disclaimer see the license and disclaimer of
16 #include <libxml/xmlmemory.h>
17 #include <libxml/parser.h>
18 #include <libxml/uri.h>
19 #include <libxml/HTMLtree.h>
21 #ifdef LIBXML_WRITER_ENABLED
23 #include <libxml/xmlwriter.h>
26 #define B64CRLF "\r\n"
29 * The following VA_COPY was coded following an example in
30 * the Samba project. It may not be sufficient for some
31 * esoteric implementations of va_list (i.e. it may need
32 * something involving a memcpy) but (hopefully) will be
33 * sufficient for libxml2.
37 #define VA_COPY(dest, src) va_copy(dest, src)
40 #define VA_COPY(dest,src) __va_copy(dest, src)
42 #define VA_COPY(dest,src) (dest) = (src)
48 * Types are kept private
51 XML_TEXTWRITER_NONE = 0,
53 XML_TEXTWRITER_ATTRIBUTE,
56 XML_TEXTWRITER_PI_TEXT,
59 XML_TEXTWRITER_DTD_TEXT,
60 XML_TEXTWRITER_DTD_ELEM,
61 XML_TEXTWRITER_DTD_ELEM_TEXT,
62 XML_TEXTWRITER_DTD_ATTL,
63 XML_TEXTWRITER_DTD_ATTL_TEXT,
64 XML_TEXTWRITER_DTD_ENTY, /* entity */
65 XML_TEXTWRITER_DTD_ENTY_TEXT,
66 XML_TEXTWRITER_DTD_PENT, /* parameter entity */
67 XML_TEXTWRITER_COMMENT
70 typedef struct _xmlTextWriterStackEntry xmlTextWriterStackEntry;
72 struct _xmlTextWriterStackEntry {
74 xmlTextWriterState state;
77 typedef struct _xmlTextWriterNsStackEntry xmlTextWriterNsStackEntry;
78 struct _xmlTextWriterNsStackEntry {
84 struct _xmlTextWriter {
85 xmlOutputBufferPtr out; /* output buffer */
86 xmlListPtr nodes; /* element name stack */
87 xmlListPtr nsstack; /* name spaces stack */
89 int indent; /* enable indent */
90 int doindent; /* internal indent flag */
91 xmlChar *ichar; /* indent character */
92 char qchar; /* character used for quoting attribute values */
93 xmlParserCtxtPtr ctxt;
98 static void xmlFreeTextWriterStackEntry(xmlLinkPtr lk);
99 static int xmlCmpTextWriterStackEntry(const void *data0,
101 static void xmlFreeTextWriterNsStackEntry(xmlLinkPtr lk);
102 static int xmlCmpTextWriterNsStackEntry(const void *data0,
104 static int xmlTextWriterWriteDocCallback(void *context,
105 const xmlChar * str, int len);
106 static int xmlTextWriterCloseDocCallback(void *context);
108 static xmlChar *xmlTextWriterVSprintf(const char *format, va_list argptr);
109 static int xmlOutputBufferWriteBase64(xmlOutputBufferPtr out, int len,
110 const unsigned char *data);
111 static void xmlTextWriterStartDocumentCallback(void *ctx);
112 static int xmlTextWriterWriteIndent(xmlTextWriterPtr writer);
114 xmlTextWriterHandleStateDependencies(xmlTextWriterPtr writer,
115 xmlTextWriterStackEntry * p);
119 * @ctxt: a writer context
120 * @error: the error number
121 * @msg: the error message
123 * Handle a writer error
126 xmlWriterErrMsg(xmlTextWriterPtr ctxt, xmlParserErrors error,
130 __xmlRaiseError(NULL, NULL, NULL, ctxt->ctxt,
131 NULL, XML_FROM_WRITER, error, XML_ERR_FATAL,
132 NULL, 0, NULL, NULL, NULL, 0, 0, msg);
134 __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_WRITER, error,
135 XML_ERR_FATAL, NULL, 0, NULL, NULL, NULL, 0, 0, msg);
140 * xmlWriterErrMsgInt:
141 * @ctxt: a writer context
142 * @error: the error number
143 * @msg: the error message
146 * Handle a writer error
149 xmlWriterErrMsgInt(xmlTextWriterPtr ctxt, xmlParserErrors error,
150 const char *msg, int val)
153 __xmlRaiseError(NULL, NULL, NULL, ctxt->ctxt,
154 NULL, XML_FROM_WRITER, error, XML_ERR_FATAL,
155 NULL, 0, NULL, NULL, NULL, val, 0, msg, val);
157 __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_WRITER, error,
158 XML_ERR_FATAL, NULL, 0, NULL, NULL, NULL, val, 0, msg, val);
164 * @out: an xmlOutputBufferPtr
166 * Create a new xmlNewTextWriter structure using an xmlOutputBufferPtr
167 * NOTE: the @out parameter will be deallocated when the writer is closed
168 * (if the call succeed.)
170 * Returns the new xmlTextWriterPtr or NULL in case of error
173 xmlNewTextWriter(xmlOutputBufferPtr out)
175 xmlTextWriterPtr ret;
177 ret = (xmlTextWriterPtr) xmlMalloc(sizeof(xmlTextWriter));
179 xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
180 "xmlNewTextWriter : out of memory!\n");
183 memset(ret, 0, (size_t) sizeof(xmlTextWriter));
185 ret->nodes = xmlListCreate((xmlListDeallocator)
186 xmlFreeTextWriterStackEntry,
188 xmlCmpTextWriterStackEntry);
189 if (ret->nodes == NULL) {
190 xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
191 "xmlNewTextWriter : out of memory!\n");
196 ret->nsstack = xmlListCreate((xmlListDeallocator)
197 xmlFreeTextWriterNsStackEntry,
199 xmlCmpTextWriterNsStackEntry);
200 if (ret->nsstack == NULL) {
201 xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
202 "xmlNewTextWriter : out of memory!\n");
203 xmlListDelete(ret->nodes);
209 ret->ichar = xmlStrdup(BAD_CAST " ");
213 xmlListDelete(ret->nodes);
214 xmlListDelete(ret->nsstack);
216 xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
217 "xmlNewTextWriter : out of memory!\n");
221 ret->doc = xmlNewDoc(NULL);
223 ret->no_doc_free = 0;
229 * xmlNewTextWriterFilename:
230 * @uri: the URI of the resource for the output
231 * @compression: compress the output?
233 * Create a new xmlNewTextWriter structure with @uri as output
235 * Returns the new xmlTextWriterPtr or NULL in case of error
238 xmlNewTextWriterFilename(const char *uri, int compression)
240 xmlTextWriterPtr ret;
241 xmlOutputBufferPtr out;
243 out = xmlOutputBufferCreateFilename(uri, NULL, compression);
245 xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
246 "xmlNewTextWriterFilename : out of memory!\n");
250 ret = xmlNewTextWriter(out);
252 xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
253 "xmlNewTextWriterFilename : out of memory!\n");
254 xmlOutputBufferClose(out);
264 * xmlNewTextWriterMemory:
266 * @compression: compress the output?
268 * Create a new xmlNewTextWriter structure with @buf as output
269 * TODO: handle compression
271 * Returns the new xmlTextWriterPtr or NULL in case of error
274 xmlNewTextWriterMemory(xmlBufferPtr buf, int compression ATTRIBUTE_UNUSED)
276 xmlTextWriterPtr ret;
277 xmlOutputBufferPtr out;
279 /*::todo handle compression */
280 out = xmlOutputBufferCreateBuffer(buf, NULL);
283 xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
284 "xmlNewTextWriterMemory : out of memory!\n");
288 ret = xmlNewTextWriter(out);
290 xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
291 "xmlNewTextWriterMemory : out of memory!\n");
292 xmlOutputBufferClose(out);
300 * xmlNewTextWriterPushParser:
301 * @ctxt: xmlParserCtxtPtr to hold the new XML document tree
302 * @compression: compress the output?
304 * Create a new xmlNewTextWriter structure with @ctxt as output
305 * NOTE: the @ctxt context will be freed with the resulting writer
306 * (if the call succeeds).
307 * TODO: handle compression
309 * Returns the new xmlTextWriterPtr or NULL in case of error
312 xmlNewTextWriterPushParser(xmlParserCtxtPtr ctxt,
313 int compression ATTRIBUTE_UNUSED)
315 xmlTextWriterPtr ret;
316 xmlOutputBufferPtr out;
319 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
320 "xmlNewTextWriterPushParser : invalid context!\n");
324 out = xmlOutputBufferCreateIO((xmlOutputWriteCallback)
325 xmlTextWriterWriteDocCallback,
326 (xmlOutputCloseCallback)
327 xmlTextWriterCloseDocCallback,
328 (void *) ctxt, NULL);
330 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
331 "xmlNewTextWriterPushParser : error at xmlOutputBufferCreateIO!\n");
335 ret = xmlNewTextWriter(out);
337 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
338 "xmlNewTextWriterPushParser : error at xmlNewTextWriter!\n");
339 xmlOutputBufferClose(out);
349 * xmlNewTextWriterDoc:
350 * @doc: address of a xmlDocPtr to hold the new XML document tree
351 * @compression: compress the output?
353 * Create a new xmlNewTextWriter structure with @*doc as output
355 * Returns the new xmlTextWriterPtr or NULL in case of error
358 xmlNewTextWriterDoc(xmlDocPtr * doc, int compression)
360 xmlTextWriterPtr ret;
361 xmlSAXHandler saxHandler;
362 xmlParserCtxtPtr ctxt;
364 memset(&saxHandler, '\0', sizeof(saxHandler));
365 xmlSAX2InitDefaultSAXHandler(&saxHandler, 1);
366 saxHandler.startDocument = xmlTextWriterStartDocumentCallback;
367 saxHandler.startElement = xmlSAX2StartElement;
368 saxHandler.endElement = xmlSAX2EndElement;
370 ctxt = xmlCreatePushParserCtxt(&saxHandler, NULL, NULL, 0, NULL);
372 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
373 "xmlNewTextWriterDoc : error at xmlCreatePushParserCtxt!\n");
377 * For some reason this seems to completely break if node names
382 ctxt->myDoc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION);
383 if (ctxt->myDoc == NULL) {
384 xmlFreeParserCtxt(ctxt);
385 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
386 "xmlNewTextWriterDoc : error at xmlNewDoc!\n");
390 ret = xmlNewTextWriterPushParser(ctxt, compression);
392 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
393 "xmlNewTextWriterDoc : error at xmlNewTextWriterPushParser!\n");
397 xmlSetDocCompressMode(ctxt->myDoc, compression);
401 ret->no_doc_free = 1;
408 * xmlNewTextWriterTree:
410 * @node: xmlNodePtr or NULL for doc->children
411 * @compression: compress the output?
413 * Create a new xmlNewTextWriter structure with @doc as output
416 * Returns the new xmlTextWriterPtr or NULL in case of error
419 xmlNewTextWriterTree(xmlDocPtr doc, xmlNodePtr node, int compression)
421 xmlTextWriterPtr ret;
422 xmlSAXHandler saxHandler;
423 xmlParserCtxtPtr ctxt;
426 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
427 "xmlNewTextWriterTree : invalid document tree!\n");
431 memset(&saxHandler, '\0', sizeof(saxHandler));
432 xmlSAX2InitDefaultSAXHandler(&saxHandler, 1);
433 saxHandler.startDocument = xmlTextWriterStartDocumentCallback;
434 saxHandler.startElement = xmlSAX2StartElement;
435 saxHandler.endElement = xmlSAX2EndElement;
437 ctxt = xmlCreatePushParserCtxt(&saxHandler, NULL, NULL, 0, NULL);
439 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
440 "xmlNewTextWriterDoc : error at xmlCreatePushParserCtxt!\n");
444 * For some reason this seems to completely break if node names
449 ret = xmlNewTextWriterPushParser(ctxt, compression);
451 xmlFreeParserCtxt(ctxt);
452 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
453 "xmlNewTextWriterDoc : error at xmlNewTextWriterPushParser!\n");
459 ret->no_doc_free = 1;
461 xmlSetDocCompressMode(doc, compression);
468 * @writer: the xmlTextWriterPtr
470 * Deallocate all the resources associated to the writer
473 xmlFreeTextWriter(xmlTextWriterPtr writer)
478 if (writer->out != NULL)
479 xmlOutputBufferClose(writer->out);
481 if (writer->nodes != NULL)
482 xmlListDelete(writer->nodes);
484 if (writer->nsstack != NULL)
485 xmlListDelete(writer->nsstack);
487 if (writer->ctxt != NULL) {
488 if ((writer->ctxt->myDoc != NULL) && (writer->no_doc_free == 0)) {
489 xmlFreeDoc(writer->ctxt->myDoc);
490 writer->ctxt->myDoc = NULL;
492 xmlFreeParserCtxt(writer->ctxt);
495 if (writer->doc != NULL)
496 xmlFreeDoc(writer->doc);
498 if (writer->ichar != NULL)
499 xmlFree(writer->ichar);
504 * xmlTextWriterStartDocument:
505 * @writer: the xmlTextWriterPtr
506 * @version: the xml version ("1.0") or NULL for default ("1.0")
507 * @encoding: the encoding or NULL for default
508 * @standalone: "yes" or "no" or NULL for default
510 * Start a new xml document
512 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
515 xmlTextWriterStartDocument(xmlTextWriterPtr writer, const char *version,
516 const char *encoding, const char *standalone)
521 xmlCharEncodingHandlerPtr encoder;
523 if ((writer == NULL) || (writer->out == NULL)) {
524 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
525 "xmlTextWriterStartDocument : invalid writer!\n");
529 lk = xmlListFront(writer->nodes);
530 if ((lk != NULL) && (xmlLinkGetData(lk) != NULL)) {
531 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
532 "xmlTextWriterStartDocument : not allowed in this context!\n");
537 if (encoding != NULL) {
538 encoder = xmlFindCharEncodingHandler(encoding);
539 if (encoder == NULL) {
540 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
541 "xmlTextWriterStartDocument : out of memory!\n");
546 writer->out->encoder = encoder;
547 if (encoder != NULL) {
548 writer->out->conv = xmlBufferCreateSize(4000);
549 xmlCharEncOutFunc(encoder, writer->out->conv, NULL);
550 if ((writer->doc != NULL) && (writer->doc->encoding == NULL))
551 writer->doc->encoding = xmlStrdup((xmlChar *)writer->out->encoder->name);
553 writer->out->conv = NULL;
556 count = xmlOutputBufferWriteString(writer->out, "<?xml version=");
560 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
565 count = xmlOutputBufferWriteString(writer->out, version);
567 count = xmlOutputBufferWriteString(writer->out, "1.0");
571 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
575 if (writer->out->encoder != 0) {
576 count = xmlOutputBufferWriteString(writer->out, " encoding=");
580 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
585 xmlOutputBufferWriteString(writer->out,
586 writer->out->encoder->name);
590 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
596 if (standalone != 0) {
597 count = xmlOutputBufferWriteString(writer->out, " standalone=");
601 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
605 count = xmlOutputBufferWriteString(writer->out, standalone);
609 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
615 count = xmlOutputBufferWriteString(writer->out, "?>\n");
624 * xmlTextWriterEndDocument:
625 * @writer: the xmlTextWriterPtr
627 * End an xml document. All open elements are closed
629 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
632 xmlTextWriterEndDocument(xmlTextWriterPtr writer)
637 xmlTextWriterStackEntry *p;
639 if (writer == NULL) {
640 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
641 "xmlTextWriterEndDocument : invalid writer!\n");
646 while ((lk = xmlListFront(writer->nodes)) != NULL) {
647 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
651 case XML_TEXTWRITER_NAME:
652 case XML_TEXTWRITER_ATTRIBUTE:
653 case XML_TEXTWRITER_TEXT:
654 count = xmlTextWriterEndElement(writer);
659 case XML_TEXTWRITER_PI:
660 case XML_TEXTWRITER_PI_TEXT:
661 count = xmlTextWriterEndPI(writer);
666 case XML_TEXTWRITER_CDATA:
667 count = xmlTextWriterEndCDATA(writer);
672 case XML_TEXTWRITER_DTD:
673 case XML_TEXTWRITER_DTD_TEXT:
674 case XML_TEXTWRITER_DTD_ELEM:
675 case XML_TEXTWRITER_DTD_ELEM_TEXT:
676 case XML_TEXTWRITER_DTD_ATTL:
677 case XML_TEXTWRITER_DTD_ATTL_TEXT:
678 case XML_TEXTWRITER_DTD_ENTY:
679 case XML_TEXTWRITER_DTD_ENTY_TEXT:
680 case XML_TEXTWRITER_DTD_PENT:
681 count = xmlTextWriterEndDTD(writer);
686 case XML_TEXTWRITER_COMMENT:
687 count = xmlTextWriterEndComment(writer);
697 if (!writer->indent) {
698 count = xmlOutputBufferWriteString(writer->out, "\n");
707 * xmlTextWriterStartComment:
708 * @writer: the xmlTextWriterPtr
710 * Start an xml comment.
712 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
715 xmlTextWriterStartComment(xmlTextWriterPtr writer)
720 xmlTextWriterStackEntry *p;
722 if (writer == NULL) {
723 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
724 "xmlTextWriterStartComment : invalid writer!\n");
729 lk = xmlListFront(writer->nodes);
731 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
734 case XML_TEXTWRITER_TEXT:
735 case XML_TEXTWRITER_NONE:
737 case XML_TEXTWRITER_NAME:
738 count = xmlOutputBufferWriteString(writer->out, ">");
742 if (writer->indent) {
744 xmlOutputBufferWriteString(writer->out, "\n");
749 p->state = XML_TEXTWRITER_TEXT;
757 p = (xmlTextWriterStackEntry *)
758 xmlMalloc(sizeof(xmlTextWriterStackEntry));
760 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
761 "xmlTextWriterStartElement : out of memory!\n");
766 p->state = XML_TEXTWRITER_COMMENT;
768 xmlListPushFront(writer->nodes, p);
770 if (writer->indent) {
771 count = xmlTextWriterWriteIndent(writer);
777 count = xmlOutputBufferWriteString(writer->out, "<!--");
786 * xmlTextWriterEndComment:
787 * @writer: the xmlTextWriterPtr
789 * End the current xml coment.
791 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
794 xmlTextWriterEndComment(xmlTextWriterPtr writer)
799 xmlTextWriterStackEntry *p;
801 if (writer == NULL) {
802 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
803 "xmlTextWriterEndComment : invalid writer!\n");
807 lk = xmlListFront(writer->nodes);
809 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
810 "xmlTextWriterEndComment : not allowed in this context!\n");
814 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
820 case XML_TEXTWRITER_COMMENT:
821 count = xmlOutputBufferWriteString(writer->out, "-->");
830 if (writer->indent) {
831 count = xmlOutputBufferWriteString(writer->out, "\n");
837 xmlListPopFront(writer->nodes);
842 * xmlTextWriterWriteFormatComment:
843 * @writer: the xmlTextWriterPtr
844 * @format: format string (see printf)
845 * @...: extra parameters for the format
847 * Write an xml comment.
849 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
852 xmlTextWriterWriteFormatComment(xmlTextWriterPtr writer,
853 const char *format, ...)
858 va_start(ap, format);
860 rc = xmlTextWriterWriteVFormatComment(writer, format, ap);
867 * xmlTextWriterWriteVFormatComment:
868 * @writer: the xmlTextWriterPtr
869 * @format: format string (see printf)
870 * @argptr: pointer to the first member of the variable argument list.
872 * Write an xml comment.
874 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
877 xmlTextWriterWriteVFormatComment(xmlTextWriterPtr writer,
878 const char *format, va_list argptr)
883 if (writer == NULL) {
884 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
885 "xmlTextWriterWriteVFormatComment : invalid writer!\n");
889 buf = xmlTextWriterVSprintf(format, argptr);
893 rc = xmlTextWriterWriteComment(writer, buf);
900 * xmlTextWriterWriteComment:
901 * @writer: the xmlTextWriterPtr
902 * @content: comment string
904 * Write an xml comment.
906 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
909 xmlTextWriterWriteComment(xmlTextWriterPtr writer, const xmlChar * content)
915 count = xmlTextWriterStartComment(writer);
919 count = xmlTextWriterWriteString(writer, content);
923 count = xmlTextWriterEndComment(writer);
932 * xmlTextWriterStartElement:
933 * @writer: the xmlTextWriterPtr
934 * @name: element name
936 * Start an xml element.
938 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
941 xmlTextWriterStartElement(xmlTextWriterPtr writer, const xmlChar * name)
946 xmlTextWriterStackEntry *p;
948 if ((writer == NULL) || (name == NULL) || (*name == '\0'))
952 lk = xmlListFront(writer->nodes);
954 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
957 case XML_TEXTWRITER_PI:
958 case XML_TEXTWRITER_PI_TEXT:
960 case XML_TEXTWRITER_NONE:
962 case XML_TEXTWRITER_ATTRIBUTE:
963 count = xmlTextWriterEndAttribute(writer);
968 case XML_TEXTWRITER_NAME:
969 count = xmlOutputBufferWriteString(writer->out, ">");
975 xmlOutputBufferWriteString(writer->out, "\n");
976 p->state = XML_TEXTWRITER_TEXT;
984 p = (xmlTextWriterStackEntry *)
985 xmlMalloc(sizeof(xmlTextWriterStackEntry));
987 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
988 "xmlTextWriterStartElement : out of memory!\n");
992 p->name = xmlStrdup(name);
994 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
995 "xmlTextWriterStartElement : out of memory!\n");
999 p->state = XML_TEXTWRITER_NAME;
1001 xmlListPushFront(writer->nodes, p);
1003 if (writer->indent) {
1004 count = xmlTextWriterWriteIndent(writer);
1008 count = xmlOutputBufferWriteString(writer->out, "<");
1013 xmlOutputBufferWriteString(writer->out, (const char *) p->name);
1022 * xmlTextWriterStartElementNS:
1023 * @writer: the xmlTextWriterPtr
1024 * @prefix: namespace prefix or NULL
1025 * @name: element local name
1026 * @namespaceURI: namespace URI or NULL
1028 * Start an xml element with namespace support.
1030 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1033 xmlTextWriterStartElementNS(xmlTextWriterPtr writer,
1034 const xmlChar * prefix, const xmlChar * name,
1035 const xmlChar * namespaceURI)
1041 if ((writer == NULL) || (name == NULL) || (*name == '\0'))
1046 buf = xmlStrdup(prefix);
1047 buf = xmlStrcat(buf, BAD_CAST ":");
1049 buf = xmlStrcat(buf, name);
1052 count = xmlTextWriterStartElement(writer, buf);
1058 if (namespaceURI != 0) {
1059 buf = xmlStrdup(BAD_CAST "xmlns");
1061 buf = xmlStrcat(buf, BAD_CAST ":");
1062 buf = xmlStrcat(buf, prefix);
1065 count = xmlTextWriterWriteAttribute(writer, buf, namespaceURI);
1076 * xmlTextWriterEndElement:
1077 * @writer: the xmlTextWriterPtr
1079 * End the current xml element.
1081 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1084 xmlTextWriterEndElement(xmlTextWriterPtr writer)
1089 xmlTextWriterStackEntry *p;
1094 lk = xmlListFront(writer->nodes);
1098 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1104 case XML_TEXTWRITER_ATTRIBUTE:
1105 count = xmlTextWriterEndAttribute(writer);
1110 case XML_TEXTWRITER_NAME:
1111 if (writer->indent) /* next element needs indent */
1112 writer->doindent = 1;
1113 count = xmlOutputBufferWriteString(writer->out, "/>");
1118 case XML_TEXTWRITER_TEXT:
1119 if ((writer->indent) && (writer->doindent)) {
1120 count = xmlTextWriterWriteIndent(writer);
1122 writer->doindent = 1;
1124 writer->doindent = 1;
1125 count = xmlOutputBufferWriteString(writer->out, "</");
1129 count = xmlOutputBufferWriteString(writer->out,
1130 (const char *) p->name);
1134 count = xmlOutputBufferWriteString(writer->out, ">");
1143 if (writer->indent) {
1144 count = xmlOutputBufferWriteString(writer->out, "\n");
1148 xmlListPopFront(writer->nodes);
1153 * xmlTextWriterFullEndElement:
1154 * @writer: the xmlTextWriterPtr
1156 * End the current xml element. Writes an end tag even if the element is empty
1158 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1161 xmlTextWriterFullEndElement(xmlTextWriterPtr writer)
1166 xmlTextWriterStackEntry *p;
1171 lk = xmlListFront(writer->nodes);
1175 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1181 case XML_TEXTWRITER_ATTRIBUTE:
1182 count = xmlTextWriterEndAttribute(writer);
1187 case XML_TEXTWRITER_NAME:
1188 count = xmlOutputBufferWriteString(writer->out, ">");
1193 case XML_TEXTWRITER_TEXT:
1194 count = xmlOutputBufferWriteString(writer->out, "</");
1198 count = xmlOutputBufferWriteString(writer->out,
1199 (const char *) p->name);
1203 count = xmlOutputBufferWriteString(writer->out, ">");
1212 xmlListPopFront(writer->nodes);
1217 * xmlTextWriterWriteFormatRaw:
1218 * @writer: the xmlTextWriterPtr
1219 * @format: format string (see printf)
1220 * @...: extra parameters for the format
1222 * Write a formatted raw xml text.
1224 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1227 xmlTextWriterWriteFormatRaw(xmlTextWriterPtr writer, const char *format,
1233 va_start(ap, format);
1235 rc = xmlTextWriterWriteVFormatRaw(writer, format, ap);
1242 * xmlTextWriterWriteVFormatRaw:
1243 * @writer: the xmlTextWriterPtr
1244 * @format: format string (see printf)
1245 * @argptr: pointer to the first member of the variable argument list.
1247 * Write a formatted raw xml text.
1249 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1252 xmlTextWriterWriteVFormatRaw(xmlTextWriterPtr writer, const char *format,
1261 buf = xmlTextWriterVSprintf(format, argptr);
1265 rc = xmlTextWriterWriteRaw(writer, buf);
1272 * xmlTextWriterWriteRawLen:
1273 * @writer: the xmlTextWriterPtr
1274 * @content: text string
1275 * @len: length of the text string
1277 * Write an xml text.
1278 * TODO: what about entities and special chars??
1280 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1283 xmlTextWriterWriteRawLen(xmlTextWriterPtr writer, const xmlChar * content,
1289 xmlTextWriterStackEntry *p;
1291 if (writer == NULL) {
1292 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
1293 "xmlTextWriterWriteRawLen : invalid writer!\n");
1297 if ((content == NULL) || (len < 0)) {
1298 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
1299 "xmlTextWriterWriteRawLen : invalid content!\n");
1304 lk = xmlListFront(writer->nodes);
1306 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1307 count = xmlTextWriterHandleStateDependencies(writer, p);
1314 writer->doindent = 0;
1316 if (content != NULL) {
1318 xmlOutputBufferWrite(writer->out, len, (const char *) content);
1328 * xmlTextWriterWriteRaw:
1329 * @writer: the xmlTextWriterPtr
1330 * @content: text string
1332 * Write a raw xml text.
1334 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1337 xmlTextWriterWriteRaw(xmlTextWriterPtr writer, const xmlChar * content)
1339 return xmlTextWriterWriteRawLen(writer, content, xmlStrlen(content));
1343 * xmlTextWriterWriteFormatString:
1344 * @writer: the xmlTextWriterPtr
1345 * @format: format string (see printf)
1346 * @...: extra parameters for the format
1348 * Write a formatted xml text.
1350 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1353 xmlTextWriterWriteFormatString(xmlTextWriterPtr writer, const char *format,
1359 if ((writer == NULL) || (format == NULL))
1362 va_start(ap, format);
1364 rc = xmlTextWriterWriteVFormatString(writer, format, ap);
1371 * xmlTextWriterWriteVFormatString:
1372 * @writer: the xmlTextWriterPtr
1373 * @format: format string (see printf)
1374 * @argptr: pointer to the first member of the variable argument list.
1376 * Write a formatted xml text.
1378 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1381 xmlTextWriterWriteVFormatString(xmlTextWriterPtr writer,
1382 const char *format, va_list argptr)
1387 if ((writer == NULL) || (format == NULL))
1390 buf = xmlTextWriterVSprintf(format, argptr);
1394 rc = xmlTextWriterWriteString(writer, buf);
1401 * xmlTextWriterWriteString:
1402 * @writer: the xmlTextWriterPtr
1403 * @content: text string
1405 * Write an xml text.
1407 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1410 xmlTextWriterWriteString(xmlTextWriterPtr writer, const xmlChar * content)
1415 xmlTextWriterStackEntry *p;
1418 if ((writer == NULL) || (content == NULL))
1422 buf = (xmlChar *) content;
1423 lk = xmlListFront(writer->nodes);
1425 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1428 case XML_TEXTWRITER_NAME:
1429 case XML_TEXTWRITER_TEXT:
1432 xmlOutputBufferWriteEscape(writer->out, content, NULL);
1434 buf = xmlEncodeSpecialChars(NULL, content);
1436 case XML_TEXTWRITER_ATTRIBUTE:
1438 xmlAttrSerializeTxtContent(writer->out->buffer, writer->doc,
1448 count = xmlTextWriterWriteRaw(writer, buf);
1453 if (buf != content) /* buf was allocated by us, so free it */
1461 * xmlOutputBufferWriteBase64:
1462 * @out: the xmlOutputBufferPtr
1463 * @data: binary data
1464 * @len: the number of bytes to encode
1466 * Write base64 encoded data to an xmlOutputBuffer.
1467 * Adapted from John Walker's base64.c (http://www.fourmilab.ch/).
1469 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1472 xmlOutputBufferWriteBase64(xmlOutputBufferPtr out, int len,
1473 const unsigned char *data)
1475 static unsigned char dtable[64] =
1476 {'A','B','C','D','E','F','G','H','I','J','K','L','M',
1477 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
1478 'a','b','c','d','e','f','g','h','i','j','k','l','m',
1479 'n','o','p','q','r','s','t','u','v','w','x','y','z',
1480 '0','1','2','3','4','5','6','7','8','9','+','/'};
1487 if ((out == NULL) || (len < 0) || (data == NULL))
1495 unsigned char igroup[3];
1496 unsigned char ogroup[4];
1500 igroup[0] = igroup[1] = igroup[2] = 0;
1501 for (n = 0; n < 3 && i < len; n++, i++) {
1503 igroup[n] = (unsigned char) c;
1507 ogroup[0] = dtable[igroup[0] >> 2];
1508 ogroup[1] = dtable[((igroup[0] & 3) << 4) | (igroup[1] >> 4)];
1510 dtable[((igroup[1] & 0xF) << 2) | (igroup[2] >> 6)];
1511 ogroup[3] = dtable[igroup[2] & 0x3F];
1520 if (linelen >= B64LINELEN) {
1521 count = xmlOutputBufferWrite(out, 2, B64CRLF);
1527 count = xmlOutputBufferWrite(out, 4, (const char *) ogroup);
1543 * xmlTextWriterWriteBase64:
1544 * @writer: the xmlTextWriterPtr
1545 * @data: binary data
1546 * @start: the position within the data of the first byte to encode
1547 * @len: the number of bytes to encode
1549 * Write an base64 encoded xml text.
1551 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1554 xmlTextWriterWriteBase64(xmlTextWriterPtr writer, const char *data,
1560 xmlTextWriterStackEntry *p;
1562 if ((writer == NULL) || (data == NULL) || (start < 0) || (len < 0))
1566 lk = xmlListFront(writer->nodes);
1568 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1570 count = xmlTextWriterHandleStateDependencies(writer, p);
1578 writer->doindent = 0;
1581 xmlOutputBufferWriteBase64(writer->out, len,
1582 (unsigned char *) data + start);
1591 * xmlOutputBufferWriteBinHex:
1592 * @out: the xmlOutputBufferPtr
1593 * @data: binary data
1594 * @len: the number of bytes to encode
1596 * Write hqx encoded data to an xmlOutputBuffer.
1599 * Returns the bytes written (may be 0 because of buffering)
1600 * or -1 in case of error
1603 xmlOutputBufferWriteBinHex(xmlOutputBufferPtr out,
1604 int len, const unsigned char *data)
1608 static char hex[16] =
1609 {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
1612 if ((out == NULL) || (data == NULL) || (len < 0)) {
1617 for (i = 0; i < len; i++) {
1619 xmlOutputBufferWrite(out, 1,
1620 (const char *) &hex[data[i] >> 4]);
1625 xmlOutputBufferWrite(out, 1,
1626 (const char *) &hex[data[i] & 0xF]);
1636 * xmlTextWriterWriteBinHex:
1637 * @writer: the xmlTextWriterPtr
1638 * @data: binary data
1639 * @start: the position within the data of the first byte to encode
1640 * @len: the number of bytes to encode
1642 * Write a BinHex encoded xml text.
1644 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1647 xmlTextWriterWriteBinHex(xmlTextWriterPtr writer, const char *data,
1653 xmlTextWriterStackEntry *p;
1655 if ((writer == NULL) || (data == NULL) || (start < 0) || (len < 0))
1659 lk = xmlListFront(writer->nodes);
1661 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1663 count = xmlTextWriterHandleStateDependencies(writer, p);
1671 writer->doindent = 0;
1674 xmlOutputBufferWriteBinHex(writer->out, len,
1675 (unsigned char *) data + start);
1684 * xmlTextWriterStartAttribute:
1685 * @writer: the xmlTextWriterPtr
1686 * @name: element name
1688 * Start an xml attribute.
1690 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1693 xmlTextWriterStartAttribute(xmlTextWriterPtr writer, const xmlChar * name)
1698 xmlTextWriterStackEntry *p;
1700 if ((writer == NULL) || (name == NULL) || (*name == '\0'))
1704 lk = xmlListFront(writer->nodes);
1708 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1713 case XML_TEXTWRITER_ATTRIBUTE:
1714 count = xmlTextWriterEndAttribute(writer);
1719 case XML_TEXTWRITER_NAME:
1720 count = xmlOutputBufferWriteString(writer->out, " ");
1725 xmlOutputBufferWriteString(writer->out,
1726 (const char *) name);
1730 count = xmlOutputBufferWriteString(writer->out, "=");
1734 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
1738 p->state = XML_TEXTWRITER_ATTRIBUTE;
1748 * xmlTextWriterStartAttributeNS:
1749 * @writer: the xmlTextWriterPtr
1750 * @prefix: namespace prefix or NULL
1751 * @name: element local name
1752 * @namespaceURI: namespace URI or NULL
1754 * Start an xml attribute with namespace support.
1756 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1759 xmlTextWriterStartAttributeNS(xmlTextWriterPtr writer,
1760 const xmlChar * prefix, const xmlChar * name,
1761 const xmlChar * namespaceURI)
1766 xmlTextWriterNsStackEntry *p;
1768 if ((writer == NULL) || (name == NULL) || (*name == '\0'))
1773 buf = xmlStrdup(prefix);
1774 buf = xmlStrcat(buf, BAD_CAST ":");
1776 buf = xmlStrcat(buf, name);
1779 count = xmlTextWriterStartAttribute(writer, buf);
1785 if (namespaceURI != 0) {
1786 buf = xmlStrdup(BAD_CAST "xmlns");
1788 buf = xmlStrcat(buf, BAD_CAST ":");
1789 buf = xmlStrcat(buf, prefix);
1792 p = (xmlTextWriterNsStackEntry *)
1793 xmlMalloc(sizeof(xmlTextWriterNsStackEntry));
1795 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
1796 "xmlTextWriterStartAttributeNS : out of memory!\n");
1801 p->uri = xmlStrdup(namespaceURI);
1803 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
1804 "xmlTextWriterStartAttributeNS : out of memory!\n");
1808 p->elem = xmlListFront(writer->nodes);
1810 xmlListPushFront(writer->nsstack, p);
1817 * xmlTextWriterEndAttribute:
1818 * @writer: the xmlTextWriterPtr
1820 * End the current xml element.
1822 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1825 xmlTextWriterEndAttribute(xmlTextWriterPtr writer)
1830 xmlTextWriterStackEntry *p;
1831 xmlTextWriterNsStackEntry *np;
1836 lk = xmlListFront(writer->nodes);
1838 xmlListDelete(writer->nsstack);
1839 writer->nsstack = NULL;
1843 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1845 xmlListDelete(writer->nsstack);
1846 writer->nsstack = NULL;
1852 case XML_TEXTWRITER_ATTRIBUTE:
1853 p->state = XML_TEXTWRITER_NAME;
1855 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
1857 xmlListDelete(writer->nsstack);
1858 writer->nsstack = NULL;
1863 while (!xmlListEmpty(writer->nsstack)) {
1864 xmlChar *namespaceURI = NULL;
1865 xmlChar *prefix = NULL;
1867 lk = xmlListFront(writer->nsstack);
1868 np = (xmlTextWriterNsStackEntry *) xmlLinkGetData(lk);
1871 namespaceURI = xmlStrdup(np->uri);
1872 prefix = xmlStrdup(np->prefix);
1875 xmlListPopFront(writer->nsstack);
1879 xmlTextWriterWriteAttribute(writer, prefix,
1881 xmlFree(namespaceURI);
1885 xmlListDelete(writer->nsstack);
1886 writer->nsstack = NULL;
1895 xmlListClear(writer->nsstack);
1903 * xmlTextWriterWriteFormatAttribute:
1904 * @writer: the xmlTextWriterPtr
1905 * @name: attribute name
1906 * @format: format string (see printf)
1907 * @...: extra parameters for the format
1909 * Write a formatted xml attribute.
1911 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1914 xmlTextWriterWriteFormatAttribute(xmlTextWriterPtr writer,
1915 const xmlChar * name, const char *format,
1921 va_start(ap, format);
1923 rc = xmlTextWriterWriteVFormatAttribute(writer, name, format, ap);
1930 * xmlTextWriterWriteVFormatAttribute:
1931 * @writer: the xmlTextWriterPtr
1932 * @name: attribute name
1933 * @format: format string (see printf)
1934 * @argptr: pointer to the first member of the variable argument list.
1936 * Write a formatted xml attribute.
1938 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1941 xmlTextWriterWriteVFormatAttribute(xmlTextWriterPtr writer,
1942 const xmlChar * name,
1943 const char *format, va_list argptr)
1951 buf = xmlTextWriterVSprintf(format, argptr);
1955 rc = xmlTextWriterWriteAttribute(writer, name, buf);
1962 * xmlTextWriterWriteAttribute:
1963 * @writer: the xmlTextWriterPtr
1964 * @name: attribute name
1965 * @content: attribute content
1967 * Write an xml attribute.
1969 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1972 xmlTextWriterWriteAttribute(xmlTextWriterPtr writer, const xmlChar * name,
1973 const xmlChar * content)
1979 count = xmlTextWriterStartAttribute(writer, name);
1983 count = xmlTextWriterWriteString(writer, content);
1987 count = xmlTextWriterEndAttribute(writer);
1996 * xmlTextWriterWriteFormatAttributeNS:
1997 * @writer: the xmlTextWriterPtr
1998 * @prefix: namespace prefix
1999 * @name: attribute local name
2000 * @namespaceURI: namespace URI
2001 * @format: format string (see printf)
2002 * @...: extra parameters for the format
2004 * Write a formatted xml attribute.with namespace support
2006 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2009 xmlTextWriterWriteFormatAttributeNS(xmlTextWriterPtr writer,
2010 const xmlChar * prefix,
2011 const xmlChar * name,
2012 const xmlChar * namespaceURI,
2013 const char *format, ...)
2018 va_start(ap, format);
2020 rc = xmlTextWriterWriteVFormatAttributeNS(writer, prefix, name,
2021 namespaceURI, format, ap);
2028 * xmlTextWriterWriteVFormatAttributeNS:
2029 * @writer: the xmlTextWriterPtr
2030 * @prefix: namespace prefix
2031 * @name: attribute local name
2032 * @namespaceURI: namespace URI
2033 * @format: format string (see printf)
2034 * @argptr: pointer to the first member of the variable argument list.
2036 * Write a formatted xml attribute.with namespace support
2038 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2041 xmlTextWriterWriteVFormatAttributeNS(xmlTextWriterPtr writer,
2042 const xmlChar * prefix,
2043 const xmlChar * name,
2044 const xmlChar * namespaceURI,
2045 const char *format, va_list argptr)
2053 buf = xmlTextWriterVSprintf(format, argptr);
2057 rc = xmlTextWriterWriteAttributeNS(writer, prefix, name, namespaceURI,
2065 * xmlTextWriterWriteAttributeNS:
2066 * @writer: the xmlTextWriterPtr
2067 * @prefix: namespace prefix
2068 * @name: attribute local name
2069 * @namespaceURI: namespace URI
2070 * @content: attribute content
2072 * Write an xml attribute.
2074 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2077 xmlTextWriterWriteAttributeNS(xmlTextWriterPtr writer,
2078 const xmlChar * prefix, const xmlChar * name,
2079 const xmlChar * namespaceURI,
2080 const xmlChar * content)
2086 if ((writer == NULL) || (name == NULL) || (*name == '\0'))
2090 if (prefix != NULL) {
2091 buf = xmlStrdup(prefix);
2092 buf = xmlStrcat(buf, BAD_CAST ":");
2094 buf = xmlStrcat(buf, name);
2097 count = xmlTextWriterWriteAttribute(writer, buf, content);
2103 if (namespaceURI != NULL) {
2105 buf = xmlStrdup(BAD_CAST "xmlns");
2106 if (prefix != NULL) {
2107 buf = xmlStrcat(buf, BAD_CAST ":");
2108 buf = xmlStrcat(buf, prefix);
2110 count = xmlTextWriterWriteAttribute(writer, buf, namespaceURI);
2120 * xmlTextWriterWriteFormatElement:
2121 * @writer: the xmlTextWriterPtr
2122 * @name: element name
2123 * @format: format string (see printf)
2124 * @...: extra parameters for the format
2126 * Write a formatted xml element.
2128 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2131 xmlTextWriterWriteFormatElement(xmlTextWriterPtr writer,
2132 const xmlChar * name, const char *format,
2138 va_start(ap, format);
2140 rc = xmlTextWriterWriteVFormatElement(writer, name, format, ap);
2147 * xmlTextWriterWriteVFormatElement:
2148 * @writer: the xmlTextWriterPtr
2149 * @name: element name
2150 * @format: format string (see printf)
2151 * @argptr: pointer to the first member of the variable argument list.
2153 * Write a formatted xml element.
2155 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2158 xmlTextWriterWriteVFormatElement(xmlTextWriterPtr writer,
2159 const xmlChar * name, const char *format,
2168 buf = xmlTextWriterVSprintf(format, argptr);
2172 rc = xmlTextWriterWriteElement(writer, name, buf);
2179 * xmlTextWriterWriteElement:
2180 * @writer: the xmlTextWriterPtr
2181 * @name: element name
2182 * @content: element content
2184 * Write an xml element.
2186 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2189 xmlTextWriterWriteElement(xmlTextWriterPtr writer, const xmlChar * name,
2190 const xmlChar * content)
2196 count = xmlTextWriterStartElement(writer, name);
2200 count = xmlTextWriterWriteString(writer, content);
2204 count = xmlTextWriterEndElement(writer);
2213 * xmlTextWriterWriteFormatElementNS:
2214 * @writer: the xmlTextWriterPtr
2215 * @prefix: namespace prefix
2216 * @name: element local name
2217 * @namespaceURI: namespace URI
2218 * @format: format string (see printf)
2219 * @...: extra parameters for the format
2221 * Write a formatted xml element with namespace support.
2223 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2226 xmlTextWriterWriteFormatElementNS(xmlTextWriterPtr writer,
2227 const xmlChar * prefix,
2228 const xmlChar * name,
2229 const xmlChar * namespaceURI,
2230 const char *format, ...)
2235 va_start(ap, format);
2237 rc = xmlTextWriterWriteVFormatElementNS(writer, prefix, name,
2238 namespaceURI, format, ap);
2245 * xmlTextWriterWriteVFormatElementNS:
2246 * @writer: the xmlTextWriterPtr
2247 * @prefix: namespace prefix
2248 * @name: element local name
2249 * @namespaceURI: namespace URI
2250 * @format: format string (see printf)
2251 * @argptr: pointer to the first member of the variable argument list.
2253 * Write a formatted xml element with namespace support.
2255 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2258 xmlTextWriterWriteVFormatElementNS(xmlTextWriterPtr writer,
2259 const xmlChar * prefix,
2260 const xmlChar * name,
2261 const xmlChar * namespaceURI,
2262 const char *format, va_list argptr)
2270 buf = xmlTextWriterVSprintf(format, argptr);
2274 rc = xmlTextWriterWriteElementNS(writer, prefix, name, namespaceURI,
2282 * xmlTextWriterWriteElementNS:
2283 * @writer: the xmlTextWriterPtr
2284 * @prefix: namespace prefix
2285 * @name: element local name
2286 * @namespaceURI: namespace URI
2287 * @content: element content
2289 * Write an xml element with namespace support.
2291 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2294 xmlTextWriterWriteElementNS(xmlTextWriterPtr writer,
2295 const xmlChar * prefix, const xmlChar * name,
2296 const xmlChar * namespaceURI,
2297 const xmlChar * content)
2302 if ((writer == NULL) || (name == NULL) || (*name == '\0'))
2307 xmlTextWriterStartElementNS(writer, prefix, name, namespaceURI);
2311 count = xmlTextWriterWriteString(writer, content);
2315 count = xmlTextWriterEndElement(writer);
2324 * xmlTextWriterStartPI:
2325 * @writer: the xmlTextWriterPtr
2326 * @target: PI target
2330 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2333 xmlTextWriterStartPI(xmlTextWriterPtr writer, const xmlChar * target)
2338 xmlTextWriterStackEntry *p;
2340 if ((writer == NULL) || (target == NULL) || (*target == '\0'))
2343 if (xmlStrcasecmp(target, (const xmlChar *) "xml") == 0) {
2344 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
2345 "xmlTextWriterStartPI : target name [Xx][Mm][Ll] is reserved for xml standardization!\n");
2350 lk = xmlListFront(writer->nodes);
2352 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
2355 case XML_TEXTWRITER_ATTRIBUTE:
2356 count = xmlTextWriterEndAttribute(writer);
2361 case XML_TEXTWRITER_NAME:
2362 count = xmlOutputBufferWriteString(writer->out, ">");
2366 p->state = XML_TEXTWRITER_TEXT;
2368 case XML_TEXTWRITER_NONE:
2369 case XML_TEXTWRITER_TEXT:
2370 case XML_TEXTWRITER_DTD:
2372 case XML_TEXTWRITER_PI:
2373 case XML_TEXTWRITER_PI_TEXT:
2374 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
2375 "xmlTextWriterStartPI : nested PI!\n");
2383 p = (xmlTextWriterStackEntry *)
2384 xmlMalloc(sizeof(xmlTextWriterStackEntry));
2386 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
2387 "xmlTextWriterStartPI : out of memory!\n");
2391 p->name = xmlStrdup(target);
2393 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
2394 "xmlTextWriterStartPI : out of memory!\n");
2398 p->state = XML_TEXTWRITER_PI;
2400 xmlListPushFront(writer->nodes, p);
2402 count = xmlOutputBufferWriteString(writer->out, "<?");
2407 xmlOutputBufferWriteString(writer->out, (const char *) p->name);
2416 * xmlTextWriterEndPI:
2417 * @writer: the xmlTextWriterPtr
2419 * End the current xml PI.
2421 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2424 xmlTextWriterEndPI(xmlTextWriterPtr writer)
2429 xmlTextWriterStackEntry *p;
2434 lk = xmlListFront(writer->nodes);
2438 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
2444 case XML_TEXTWRITER_PI:
2445 case XML_TEXTWRITER_PI_TEXT:
2446 count = xmlOutputBufferWriteString(writer->out, "?>");
2455 if (writer->indent) {
2456 count = xmlOutputBufferWriteString(writer->out, "\n");
2462 xmlListPopFront(writer->nodes);
2467 * xmlTextWriterWriteFormatPI:
2468 * @writer: the xmlTextWriterPtr
2469 * @target: PI target
2470 * @format: format string (see printf)
2471 * @...: extra parameters for the format
2473 * Write a formatted PI.
2475 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2478 xmlTextWriterWriteFormatPI(xmlTextWriterPtr writer, const xmlChar * target,
2479 const char *format, ...)
2484 va_start(ap, format);
2486 rc = xmlTextWriterWriteVFormatPI(writer, target, format, ap);
2493 * xmlTextWriterWriteVFormatPI:
2494 * @writer: the xmlTextWriterPtr
2495 * @target: PI target
2496 * @format: format string (see printf)
2497 * @argptr: pointer to the first member of the variable argument list.
2499 * Write a formatted xml PI.
2501 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2504 xmlTextWriterWriteVFormatPI(xmlTextWriterPtr writer,
2505 const xmlChar * target, const char *format,
2514 buf = xmlTextWriterVSprintf(format, argptr);
2518 rc = xmlTextWriterWritePI(writer, target, buf);
2525 * xmlTextWriterWritePI:
2526 * @writer: the xmlTextWriterPtr
2527 * @target: PI target
2528 * @content: PI content
2532 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2535 xmlTextWriterWritePI(xmlTextWriterPtr writer, const xmlChar * target,
2536 const xmlChar * content)
2542 count = xmlTextWriterStartPI(writer, target);
2547 count = xmlTextWriterWriteString(writer, content);
2552 count = xmlTextWriterEndPI(writer);
2561 * xmlTextWriterStartCDATA:
2562 * @writer: the xmlTextWriterPtr
2564 * Start an xml CDATA section.
2566 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2569 xmlTextWriterStartCDATA(xmlTextWriterPtr writer)
2574 xmlTextWriterStackEntry *p;
2580 lk = xmlListFront(writer->nodes);
2582 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
2585 case XML_TEXTWRITER_NONE:
2586 case XML_TEXTWRITER_PI:
2587 case XML_TEXTWRITER_PI_TEXT:
2589 case XML_TEXTWRITER_ATTRIBUTE:
2590 count = xmlTextWriterEndAttribute(writer);
2595 case XML_TEXTWRITER_NAME:
2596 count = xmlOutputBufferWriteString(writer->out, ">");
2600 p->state = XML_TEXTWRITER_TEXT;
2602 case XML_TEXTWRITER_CDATA:
2603 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
2604 "xmlTextWriterStartCDATA : CDATA not allowed in this context!\n");
2612 p = (xmlTextWriterStackEntry *)
2613 xmlMalloc(sizeof(xmlTextWriterStackEntry));
2615 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
2616 "xmlTextWriterStartCDATA : out of memory!\n");
2621 p->state = XML_TEXTWRITER_CDATA;
2623 xmlListPushFront(writer->nodes, p);
2625 count = xmlOutputBufferWriteString(writer->out, "<![CDATA[");
2634 * xmlTextWriterEndCDATA:
2635 * @writer: the xmlTextWriterPtr
2637 * End an xml CDATA section.
2639 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2642 xmlTextWriterEndCDATA(xmlTextWriterPtr writer)
2647 xmlTextWriterStackEntry *p;
2652 lk = xmlListFront(writer->nodes);
2656 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
2662 case XML_TEXTWRITER_CDATA:
2663 count = xmlOutputBufferWriteString(writer->out, "]]>");
2672 xmlListPopFront(writer->nodes);
2677 * xmlTextWriterWriteFormatCDATA:
2678 * @writer: the xmlTextWriterPtr
2679 * @format: format string (see printf)
2680 * @...: extra parameters for the format
2682 * Write a formatted xml CDATA.
2684 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2687 xmlTextWriterWriteFormatCDATA(xmlTextWriterPtr writer, const char *format,
2693 va_start(ap, format);
2695 rc = xmlTextWriterWriteVFormatCDATA(writer, format, ap);
2702 * xmlTextWriterWriteVFormatCDATA:
2703 * @writer: the xmlTextWriterPtr
2704 * @format: format string (see printf)
2705 * @argptr: pointer to the first member of the variable argument list.
2707 * Write a formatted xml CDATA.
2709 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2712 xmlTextWriterWriteVFormatCDATA(xmlTextWriterPtr writer, const char *format,
2721 buf = xmlTextWriterVSprintf(format, argptr);
2725 rc = xmlTextWriterWriteCDATA(writer, buf);
2732 * xmlTextWriterWriteCDATA:
2733 * @writer: the xmlTextWriterPtr
2734 * @content: CDATA content
2736 * Write an xml CDATA.
2738 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2741 xmlTextWriterWriteCDATA(xmlTextWriterPtr writer, const xmlChar * content)
2747 count = xmlTextWriterStartCDATA(writer);
2752 count = xmlTextWriterWriteString(writer, content);
2757 count = xmlTextWriterEndCDATA(writer);
2766 * xmlTextWriterStartDTD:
2767 * @writer: the xmlTextWriterPtr
2768 * @name: the name of the DTD
2769 * @pubid: the public identifier, which is an alternative to the system identifier
2770 * @sysid: the system identifier, which is the URI of the DTD
2774 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2777 xmlTextWriterStartDTD(xmlTextWriterPtr writer,
2778 const xmlChar * name,
2779 const xmlChar * pubid, const xmlChar * sysid)
2784 xmlTextWriterStackEntry *p;
2786 if (writer == NULL || name == NULL || *name == '\0')
2790 lk = xmlListFront(writer->nodes);
2791 if ((lk != NULL) && (xmlLinkGetData(lk) != NULL)) {
2792 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
2793 "xmlTextWriterStartDTD : DTD allowed only in prolog!\n");
2797 p = (xmlTextWriterStackEntry *)
2798 xmlMalloc(sizeof(xmlTextWriterStackEntry));
2800 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
2801 "xmlTextWriterStartDTD : out of memory!\n");
2805 p->name = xmlStrdup(name);
2807 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
2808 "xmlTextWriterStartDTD : out of memory!\n");
2812 p->state = XML_TEXTWRITER_DTD;
2814 xmlListPushFront(writer->nodes, p);
2816 count = xmlOutputBufferWriteString(writer->out, "<!DOCTYPE ");
2820 count = xmlOutputBufferWriteString(writer->out, (const char *) name);
2827 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
2828 "xmlTextWriterStartDTD : system identifier needed!\n");
2833 count = xmlOutputBufferWrite(writer->out, 1, "\n");
2835 count = xmlOutputBufferWrite(writer->out, 1, " ");
2840 count = xmlOutputBufferWriteString(writer->out, "PUBLIC ");
2845 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
2851 xmlOutputBufferWriteString(writer->out, (const char *) pubid);
2856 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
2865 count = xmlOutputBufferWrite(writer->out, 1, "\n");
2867 count = xmlOutputBufferWrite(writer->out, 1, " ");
2871 count = xmlOutputBufferWriteString(writer->out, "SYSTEM ");
2877 count = xmlOutputBufferWriteString(writer->out, "\n ");
2879 count = xmlOutputBufferWrite(writer->out, 1, " ");
2885 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
2891 xmlOutputBufferWriteString(writer->out, (const char *) sysid);
2896 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
2906 * xmlTextWriterEndDTD:
2907 * @writer: the xmlTextWriterPtr
2911 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2914 xmlTextWriterEndDTD(xmlTextWriterPtr writer)
2920 xmlTextWriterStackEntry *p;
2928 lk = xmlListFront(writer->nodes);
2931 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
2935 case XML_TEXTWRITER_DTD_TEXT:
2936 count = xmlOutputBufferWriteString(writer->out, "]");
2941 case XML_TEXTWRITER_DTD:
2942 count = xmlOutputBufferWriteString(writer->out, ">");
2944 if (writer->indent) {
2948 count = xmlOutputBufferWriteString(writer->out, "\n");
2951 xmlListPopFront(writer->nodes);
2953 case XML_TEXTWRITER_DTD_ELEM:
2954 case XML_TEXTWRITER_DTD_ELEM_TEXT:
2955 count = xmlTextWriterEndDTDElement(writer);
2957 case XML_TEXTWRITER_DTD_ATTL:
2958 case XML_TEXTWRITER_DTD_ATTL_TEXT:
2959 count = xmlTextWriterEndDTDAttlist(writer);
2961 case XML_TEXTWRITER_DTD_ENTY:
2962 case XML_TEXTWRITER_DTD_PENT:
2963 case XML_TEXTWRITER_DTD_ENTY_TEXT:
2964 count = xmlTextWriterEndDTDEntity(writer);
2966 case XML_TEXTWRITER_COMMENT:
2967 count = xmlTextWriterEndComment(writer);
2983 * xmlTextWriterWriteFormatDTD:
2984 * @writer: the xmlTextWriterPtr
2985 * @name: the name of the DTD
2986 * @pubid: the public identifier, which is an alternative to the system identifier
2987 * @sysid: the system identifier, which is the URI of the DTD
2988 * @format: format string (see printf)
2989 * @...: extra parameters for the format
2991 * Write a DTD with a formatted markup declarations part.
2993 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2996 xmlTextWriterWriteFormatDTD(xmlTextWriterPtr writer,
2997 const xmlChar * name,
2998 const xmlChar * pubid,
2999 const xmlChar * sysid, const char *format, ...)
3004 va_start(ap, format);
3006 rc = xmlTextWriterWriteVFormatDTD(writer, name, pubid, sysid, format,
3014 * xmlTextWriterWriteVFormatDTD:
3015 * @writer: the xmlTextWriterPtr
3016 * @name: the name of the DTD
3017 * @pubid: the public identifier, which is an alternative to the system identifier
3018 * @sysid: the system identifier, which is the URI of the DTD
3019 * @format: format string (see printf)
3020 * @argptr: pointer to the first member of the variable argument list.
3022 * Write a DTD with a formatted markup declarations part.
3024 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3027 xmlTextWriterWriteVFormatDTD(xmlTextWriterPtr writer,
3028 const xmlChar * name,
3029 const xmlChar * pubid,
3030 const xmlChar * sysid,
3031 const char *format, va_list argptr)
3039 buf = xmlTextWriterVSprintf(format, argptr);
3043 rc = xmlTextWriterWriteDTD(writer, name, pubid, sysid, buf);
3050 * xmlTextWriterWriteDTD:
3051 * @writer: the xmlTextWriterPtr
3052 * @name: the name of the DTD
3053 * @pubid: the public identifier, which is an alternative to the system identifier
3054 * @sysid: the system identifier, which is the URI of the DTD
3055 * @subset: string content of the DTD
3059 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3062 xmlTextWriterWriteDTD(xmlTextWriterPtr writer,
3063 const xmlChar * name,
3064 const xmlChar * pubid,
3065 const xmlChar * sysid, const xmlChar * subset)
3071 count = xmlTextWriterStartDTD(writer, name, pubid, sysid);
3076 count = xmlTextWriterWriteString(writer, subset);
3081 count = xmlTextWriterEndDTD(writer);
3090 * xmlTextWriterStartDTDElement:
3091 * @writer: the xmlTextWriterPtr
3092 * @name: the name of the DTD element
3094 * Start an xml DTD element.
3096 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3099 xmlTextWriterStartDTDElement(xmlTextWriterPtr writer, const xmlChar * name)
3104 xmlTextWriterStackEntry *p;
3106 if (writer == NULL || name == NULL || *name == '\0')
3110 lk = xmlListFront(writer->nodes);
3115 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3118 case XML_TEXTWRITER_DTD:
3119 count = xmlOutputBufferWriteString(writer->out, " [");
3123 if (writer->indent) {
3124 count = xmlOutputBufferWriteString(writer->out, "\n");
3129 p->state = XML_TEXTWRITER_DTD_TEXT;
3131 case XML_TEXTWRITER_DTD_TEXT:
3132 case XML_TEXTWRITER_NONE:
3139 p = (xmlTextWriterStackEntry *)
3140 xmlMalloc(sizeof(xmlTextWriterStackEntry));
3142 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
3143 "xmlTextWriterStartDTDElement : out of memory!\n");
3147 p->name = xmlStrdup(name);
3149 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
3150 "xmlTextWriterStartDTDElement : out of memory!\n");
3154 p->state = XML_TEXTWRITER_DTD_ELEM;
3156 xmlListPushFront(writer->nodes, p);
3158 if (writer->indent) {
3159 count = xmlTextWriterWriteIndent(writer);
3165 count = xmlOutputBufferWriteString(writer->out, "<!ELEMENT ");
3169 count = xmlOutputBufferWriteString(writer->out, (const char *) name);
3178 * xmlTextWriterEndDTDElement:
3179 * @writer: the xmlTextWriterPtr
3181 * End an xml DTD element.
3183 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3186 xmlTextWriterEndDTDElement(xmlTextWriterPtr writer)
3191 xmlTextWriterStackEntry *p;
3197 lk = xmlListFront(writer->nodes);
3201 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3206 case XML_TEXTWRITER_DTD_ELEM:
3207 case XML_TEXTWRITER_DTD_ELEM_TEXT:
3208 count = xmlOutputBufferWriteString(writer->out, ">");
3217 if (writer->indent) {
3218 count = xmlOutputBufferWriteString(writer->out, "\n");
3224 xmlListPopFront(writer->nodes);
3229 * xmlTextWriterWriteFormatDTDElement:
3230 * @writer: the xmlTextWriterPtr
3231 * @name: the name of the DTD element
3232 * @format: format string (see printf)
3233 * @...: extra parameters for the format
3235 * Write a formatted DTD element.
3237 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3240 xmlTextWriterWriteFormatDTDElement(xmlTextWriterPtr writer,
3241 const xmlChar * name,
3242 const char *format, ...)
3247 va_start(ap, format);
3249 rc = xmlTextWriterWriteVFormatDTDElement(writer, name, format, ap);
3256 * xmlTextWriterWriteVFormatDTDElement:
3257 * @writer: the xmlTextWriterPtr
3258 * @name: the name of the DTD element
3259 * @format: format string (see printf)
3260 * @argptr: pointer to the first member of the variable argument list.
3262 * Write a formatted DTD element.
3264 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3267 xmlTextWriterWriteVFormatDTDElement(xmlTextWriterPtr writer,
3268 const xmlChar * name,
3269 const char *format, va_list argptr)
3277 buf = xmlTextWriterVSprintf(format, argptr);
3281 rc = xmlTextWriterWriteDTDElement(writer, name, buf);
3288 * xmlTextWriterWriteDTDElement:
3289 * @writer: the xmlTextWriterPtr
3290 * @name: the name of the DTD element
3291 * @content: content of the element
3293 * Write a DTD element.
3295 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3298 xmlTextWriterWriteDTDElement(xmlTextWriterPtr writer,
3299 const xmlChar * name, const xmlChar * content)
3304 if (content == NULL)
3308 count = xmlTextWriterStartDTDElement(writer, name);
3313 count = xmlTextWriterWriteString(writer, content);
3318 count = xmlTextWriterEndDTDElement(writer);
3327 * xmlTextWriterStartDTDAttlist:
3328 * @writer: the xmlTextWriterPtr
3329 * @name: the name of the DTD ATTLIST
3331 * Start an xml DTD ATTLIST.
3333 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3336 xmlTextWriterStartDTDAttlist(xmlTextWriterPtr writer, const xmlChar * name)
3341 xmlTextWriterStackEntry *p;
3343 if (writer == NULL || name == NULL || *name == '\0')
3347 lk = xmlListFront(writer->nodes);
3352 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3355 case XML_TEXTWRITER_DTD:
3356 count = xmlOutputBufferWriteString(writer->out, " [");
3360 if (writer->indent) {
3361 count = xmlOutputBufferWriteString(writer->out, "\n");
3366 p->state = XML_TEXTWRITER_DTD_TEXT;
3368 case XML_TEXTWRITER_DTD_TEXT:
3369 case XML_TEXTWRITER_NONE:
3376 p = (xmlTextWriterStackEntry *)
3377 xmlMalloc(sizeof(xmlTextWriterStackEntry));
3379 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
3380 "xmlTextWriterStartDTDAttlist : out of memory!\n");
3384 p->name = xmlStrdup(name);
3386 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
3387 "xmlTextWriterStartDTDAttlist : out of memory!\n");
3391 p->state = XML_TEXTWRITER_DTD_ATTL;
3393 xmlListPushFront(writer->nodes, p);
3395 if (writer->indent) {
3396 count = xmlTextWriterWriteIndent(writer);
3402 count = xmlOutputBufferWriteString(writer->out, "<!ATTLIST ");
3406 count = xmlOutputBufferWriteString(writer->out, (const char *) name);
3415 * xmlTextWriterEndDTDAttlist:
3416 * @writer: the xmlTextWriterPtr
3418 * End an xml DTD attribute list.
3420 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3423 xmlTextWriterEndDTDAttlist(xmlTextWriterPtr writer)
3428 xmlTextWriterStackEntry *p;
3434 lk = xmlListFront(writer->nodes);
3438 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3443 case XML_TEXTWRITER_DTD_ATTL:
3444 case XML_TEXTWRITER_DTD_ATTL_TEXT:
3445 count = xmlOutputBufferWriteString(writer->out, ">");
3454 if (writer->indent) {
3455 count = xmlOutputBufferWriteString(writer->out, "\n");
3461 xmlListPopFront(writer->nodes);
3466 * xmlTextWriterWriteFormatDTDAttlist:
3467 * @writer: the xmlTextWriterPtr
3468 * @name: the name of the DTD ATTLIST
3469 * @format: format string (see printf)
3470 * @...: extra parameters for the format
3472 * Write a formatted DTD ATTLIST.
3474 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3477 xmlTextWriterWriteFormatDTDAttlist(xmlTextWriterPtr writer,
3478 const xmlChar * name,
3479 const char *format, ...)
3484 va_start(ap, format);
3486 rc = xmlTextWriterWriteVFormatDTDAttlist(writer, name, format, ap);
3493 * xmlTextWriterWriteVFormatDTDAttlist:
3494 * @writer: the xmlTextWriterPtr
3495 * @name: the name of the DTD ATTLIST
3496 * @format: format string (see printf)
3497 * @argptr: pointer to the first member of the variable argument list.
3499 * Write a formatted DTD ATTLIST.
3501 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3504 xmlTextWriterWriteVFormatDTDAttlist(xmlTextWriterPtr writer,
3505 const xmlChar * name,
3506 const char *format, va_list argptr)
3514 buf = xmlTextWriterVSprintf(format, argptr);
3518 rc = xmlTextWriterWriteDTDAttlist(writer, name, buf);
3525 * xmlTextWriterWriteDTDAttlist:
3526 * @writer: the xmlTextWriterPtr
3527 * @name: the name of the DTD ATTLIST
3528 * @content: content of the ATTLIST
3530 * Write a DTD ATTLIST.
3532 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3535 xmlTextWriterWriteDTDAttlist(xmlTextWriterPtr writer,
3536 const xmlChar * name, const xmlChar * content)
3541 if (content == NULL)
3545 count = xmlTextWriterStartDTDAttlist(writer, name);
3550 count = xmlTextWriterWriteString(writer, content);
3555 count = xmlTextWriterEndDTDAttlist(writer);
3564 * xmlTextWriterStartDTDEntity:
3565 * @writer: the xmlTextWriterPtr
3566 * @pe: TRUE if this is a parameter entity, FALSE if not
3567 * @name: the name of the DTD ATTLIST
3569 * Start an xml DTD ATTLIST.
3571 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3574 xmlTextWriterStartDTDEntity(xmlTextWriterPtr writer,
3575 int pe, const xmlChar * name)
3580 xmlTextWriterStackEntry *p;
3582 if (writer == NULL || name == NULL || *name == '\0')
3586 lk = xmlListFront(writer->nodes);
3589 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3592 case XML_TEXTWRITER_DTD:
3593 count = xmlOutputBufferWriteString(writer->out, " [");
3597 if (writer->indent) {
3599 xmlOutputBufferWriteString(writer->out, "\n");
3604 p->state = XML_TEXTWRITER_DTD_TEXT;
3606 case XML_TEXTWRITER_DTD_TEXT:
3607 case XML_TEXTWRITER_NONE:
3615 p = (xmlTextWriterStackEntry *)
3616 xmlMalloc(sizeof(xmlTextWriterStackEntry));
3618 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
3619 "xmlTextWriterStartDTDElement : out of memory!\n");
3623 p->name = xmlStrdup(name);
3625 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
3626 "xmlTextWriterStartDTDElement : out of memory!\n");
3632 p->state = XML_TEXTWRITER_DTD_PENT;
3634 p->state = XML_TEXTWRITER_DTD_ENTY;
3636 xmlListPushFront(writer->nodes, p);
3638 if (writer->indent) {
3639 count = xmlTextWriterWriteIndent(writer);
3645 count = xmlOutputBufferWriteString(writer->out, "<!ENTITY ");
3651 count = xmlOutputBufferWriteString(writer->out, "% ");
3657 count = xmlOutputBufferWriteString(writer->out, (const char *) name);
3666 * xmlTextWriterEndDTDEntity:
3667 * @writer: the xmlTextWriterPtr
3669 * End an xml DTD entity.
3671 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3674 xmlTextWriterEndDTDEntity(xmlTextWriterPtr writer)
3679 xmlTextWriterStackEntry *p;
3685 lk = xmlListFront(writer->nodes);
3689 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3694 case XML_TEXTWRITER_DTD_ENTY_TEXT:
3695 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
3699 case XML_TEXTWRITER_DTD_ENTY:
3700 case XML_TEXTWRITER_DTD_PENT:
3701 count = xmlOutputBufferWriteString(writer->out, ">");
3710 if (writer->indent) {
3711 count = xmlOutputBufferWriteString(writer->out, "\n");
3717 xmlListPopFront(writer->nodes);
3722 * xmlTextWriterWriteFormatDTDInternalEntity:
3723 * @writer: the xmlTextWriterPtr
3724 * @pe: TRUE if this is a parameter entity, FALSE if not
3725 * @name: the name of the DTD entity
3726 * @format: format string (see printf)
3727 * @...: extra parameters for the format
3729 * Write a formatted DTD internal entity.
3731 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3734 xmlTextWriterWriteFormatDTDInternalEntity(xmlTextWriterPtr writer,
3736 const xmlChar * name,
3737 const char *format, ...)
3742 va_start(ap, format);
3744 rc = xmlTextWriterWriteVFormatDTDInternalEntity(writer, pe, name,
3752 * xmlTextWriterWriteVFormatDTDInternalEntity:
3753 * @writer: the xmlTextWriterPtr
3754 * @pe: TRUE if this is a parameter entity, FALSE if not
3755 * @name: the name of the DTD entity
3756 * @format: format string (see printf)
3757 * @argptr: pointer to the first member of the variable argument list.
3759 * Write a formatted DTD internal entity.
3761 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3764 xmlTextWriterWriteVFormatDTDInternalEntity(xmlTextWriterPtr writer,
3766 const xmlChar * name,
3776 buf = xmlTextWriterVSprintf(format, argptr);
3780 rc = xmlTextWriterWriteDTDInternalEntity(writer, pe, name, buf);
3787 * xmlTextWriterWriteDTDEntity:
3788 * @writer: the xmlTextWriterPtr
3789 * @pe: TRUE if this is a parameter entity, FALSE if not
3790 * @name: the name of the DTD entity
3791 * @pubid: the public identifier, which is an alternative to the system identifier
3792 * @sysid: the system identifier, which is the URI of the DTD
3793 * @ndataid: the xml notation name.
3794 * @content: content of the entity
3796 * Write a DTD entity.
3798 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3801 xmlTextWriterWriteDTDEntity(xmlTextWriterPtr writer,
3803 const xmlChar * name,
3804 const xmlChar * pubid,
3805 const xmlChar * sysid,
3806 const xmlChar * ndataid,
3807 const xmlChar * content)
3809 if ((content == NULL) && (pubid == NULL) && (sysid == NULL))
3811 if ((pe != 0) && (ndataid != NULL))
3814 if ((pubid == NULL) && (sysid == NULL))
3815 return xmlTextWriterWriteDTDInternalEntity(writer, pe, name,
3818 return xmlTextWriterWriteDTDExternalEntity(writer, pe, name, pubid,
3823 * xmlTextWriterWriteDTDInternalEntity:
3824 * @writer: the xmlTextWriterPtr
3825 * @pe: TRUE if this is a parameter entity, FALSE if not
3826 * @name: the name of the DTD entity
3827 * @content: content of the entity
3829 * Write a DTD internal entity.
3831 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3834 xmlTextWriterWriteDTDInternalEntity(xmlTextWriterPtr writer,
3836 const xmlChar * name,
3837 const xmlChar * content)
3842 if ((name == NULL) || (*name == '\0') || (content == NULL))
3846 count = xmlTextWriterStartDTDEntity(writer, pe, name);
3851 count = xmlTextWriterWriteString(writer, content);
3856 count = xmlTextWriterEndDTDEntity(writer);
3865 * xmlTextWriterWriteDTDExternalEntity:
3866 * @writer: the xmlTextWriterPtr
3867 * @pe: TRUE if this is a parameter entity, FALSE if not
3868 * @name: the name of the DTD entity
3869 * @pubid: the public identifier, which is an alternative to the system identifier
3870 * @sysid: the system identifier, which is the URI of the DTD
3871 * @ndataid: the xml notation name.
3873 * Write a DTD external entity. The entity must have been started with xmlTextWriterStartDTDEntity
3875 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3878 xmlTextWriterWriteDTDExternalEntity(xmlTextWriterPtr writer,
3880 const xmlChar * name,
3881 const xmlChar * pubid,
3882 const xmlChar * sysid,
3883 const xmlChar * ndataid)
3888 if (((pubid == NULL) && (sysid == NULL)))
3890 if ((pe != 0) && (ndataid != NULL))
3894 count = xmlTextWriterStartDTDEntity(writer, pe, name);
3900 xmlTextWriterWriteDTDExternalEntityContents(writer, pubid, sysid,
3906 count = xmlTextWriterEndDTDEntity(writer);
3915 * xmlTextWriterWriteDTDExternalEntityContents:
3916 * @writer: the xmlTextWriterPtr
3917 * @pubid: the public identifier, which is an alternative to the system identifier
3918 * @sysid: the system identifier, which is the URI of the DTD
3919 * @ndataid: the xml notation name.
3921 * Write the contents of a DTD external entity.
3923 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3926 xmlTextWriterWriteDTDExternalEntityContents(xmlTextWriterPtr writer,
3927 const xmlChar * pubid,
3928 const xmlChar * sysid,
3929 const xmlChar * ndataid)
3934 xmlTextWriterStackEntry *p;
3936 if (writer == NULL) {
3937 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
3938 "xmlTextWriterWriteDTDExternalEntityContents: xmlTextWriterPtr invalid!\n");
3943 lk = xmlListFront(writer->nodes);
3945 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
3946 "xmlTextWriterWriteDTDExternalEntityContents: you must call xmlTextWriterStartDTDEntity before the call to this function!\n");
3950 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3955 case XML_TEXTWRITER_DTD_ENTY:
3957 case XML_TEXTWRITER_DTD_PENT:
3958 if (ndataid != NULL) {
3959 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
3960 "xmlTextWriterWriteDTDExternalEntityContents: notation not allowed with parameter entities!\n");
3965 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
3966 "xmlTextWriterWriteDTDExternalEntityContents: you must call xmlTextWriterStartDTDEntity before the call to this function!\n");
3972 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
3973 "xmlTextWriterWriteDTDExternalEntityContents: system identifier needed!\n");
3977 count = xmlOutputBufferWriteString(writer->out, " PUBLIC ");
3982 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
3988 xmlOutputBufferWriteString(writer->out, (const char *) pubid);
3993 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
4001 count = xmlOutputBufferWriteString(writer->out, " SYSTEM");
4007 count = xmlOutputBufferWriteString(writer->out, " ");
4012 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
4018 xmlOutputBufferWriteString(writer->out, (const char *) sysid);
4023 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
4029 if (ndataid != NULL) {
4030 count = xmlOutputBufferWriteString(writer->out, " NDATA ");
4036 xmlOutputBufferWriteString(writer->out,
4037 (const char *) ndataid);
4047 * xmlTextWriterWriteDTDNotation:
4048 * @writer: the xmlTextWriterPtr
4049 * @name: the name of the xml notation
4050 * @pubid: the public identifier, which is an alternative to the system identifier
4051 * @sysid: the system identifier, which is the URI of the DTD
4053 * Write a DTD entity.
4055 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
4058 xmlTextWriterWriteDTDNotation(xmlTextWriterPtr writer,
4059 const xmlChar * name,
4060 const xmlChar * pubid, const xmlChar * sysid)
4065 xmlTextWriterStackEntry *p;
4067 if (writer == NULL || name == NULL || *name == '\0')
4071 lk = xmlListFront(writer->nodes);
4076 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
4079 case XML_TEXTWRITER_DTD:
4080 count = xmlOutputBufferWriteString(writer->out, " [");
4084 if (writer->indent) {
4085 count = xmlOutputBufferWriteString(writer->out, "\n");
4090 p->state = XML_TEXTWRITER_DTD_TEXT;
4092 case XML_TEXTWRITER_DTD_TEXT:
4099 if (writer->indent) {
4100 count = xmlTextWriterWriteIndent(writer);
4106 count = xmlOutputBufferWriteString(writer->out, "<!NOTATION ");
4110 count = xmlOutputBufferWriteString(writer->out, (const char *) name);
4116 count = xmlOutputBufferWriteString(writer->out, " PUBLIC ");
4120 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
4125 xmlOutputBufferWriteString(writer->out, (const char *) pubid);
4129 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
4137 count = xmlOutputBufferWriteString(writer->out, " SYSTEM");
4142 count = xmlOutputBufferWriteString(writer->out, " ");
4146 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
4151 xmlOutputBufferWriteString(writer->out, (const char *) sysid);
4155 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
4161 count = xmlOutputBufferWriteString(writer->out, ">");
4170 * xmlTextWriterFlush:
4171 * @writer: the xmlTextWriterPtr
4173 * Flush the output buffer.
4175 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
4178 xmlTextWriterFlush(xmlTextWriterPtr writer)
4185 if (writer->out == NULL)
4188 count = xmlOutputBufferFlush(writer->out);
4198 * xmlFreeTextWriterStackEntry:
4199 * @lk: the xmlLinkPtr
4201 * Free callback for the xmlList.
4204 xmlFreeTextWriterStackEntry(xmlLinkPtr lk)
4206 xmlTextWriterStackEntry *p;
4208 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
4218 * xmlCmpTextWriterStackEntry:
4219 * @data0: the first data
4220 * @data1: the second data
4222 * Compare callback for the xmlList.
4227 xmlCmpTextWriterStackEntry(const void *data0, const void *data1)
4229 xmlTextWriterStackEntry *p0;
4230 xmlTextWriterStackEntry *p1;
4241 p0 = (xmlTextWriterStackEntry *) data0;
4242 p1 = (xmlTextWriterStackEntry *) data1;
4244 return xmlStrcmp(p0->name, p1->name);
4252 * xmlFreeTextWriterNsStackEntry:
4253 * @lk: the xmlLinkPtr
4255 * Free callback for the xmlList.
4258 xmlFreeTextWriterNsStackEntry(xmlLinkPtr lk)
4260 xmlTextWriterNsStackEntry *p;
4262 p = (xmlTextWriterNsStackEntry *) xmlLinkGetData(lk);
4275 * xmlCmpTextWriterNsStackEntry:
4276 * @data0: the first data
4277 * @data1: the second data
4279 * Compare callback for the xmlList.
4284 xmlCmpTextWriterNsStackEntry(const void *data0, const void *data1)
4286 xmlTextWriterNsStackEntry *p0;
4287 xmlTextWriterNsStackEntry *p1;
4299 p0 = (xmlTextWriterNsStackEntry *) data0;
4300 p1 = (xmlTextWriterNsStackEntry *) data1;
4302 rc = xmlStrcmp(p0->prefix, p1->prefix);
4305 rc = p0->elem == p1->elem;
4311 * xmlTextWriterWriteDocCallback:
4312 * @context: the xmlBufferPtr
4313 * @str: the data to write
4314 * @len: the length of the data
4316 * Write callback for the xmlOutputBuffer with target xmlBuffer
4321 xmlTextWriterWriteDocCallback(void *context, const xmlChar * str, int len)
4323 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) context;
4326 if ((rc = xmlParseChunk(ctxt, (const char *) str, len, 0)) != 0) {
4327 xmlWriterErrMsgInt(NULL, XML_ERR_INTERNAL_ERROR,
4328 "xmlTextWriterWriteDocCallback : XML error %d !\n",
4337 * xmlTextWriterCloseDocCallback:
4338 * @context: the xmlBufferPtr
4340 * Close callback for the xmlOutputBuffer with target xmlBuffer
4345 xmlTextWriterCloseDocCallback(void *context)
4347 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) context;
4350 if ((rc = xmlParseChunk(ctxt, NULL, 0, 1)) != 0) {
4351 xmlWriterErrMsgInt(NULL, XML_ERR_INTERNAL_ERROR,
4352 "xmlTextWriterWriteDocCallback : XML error %d !\n",
4361 * xmlTextWriterVSprintf:
4362 * @format: see printf
4363 * @argptr: pointer to the first member of the variable argument list.
4365 * Utility function for formatted output
4367 * Returns a new xmlChar buffer with the data or NULL on error. This buffer must be freed.
4370 xmlTextWriterVSprintf(const char *format, va_list argptr)
4378 buf = (xmlChar *) xmlMalloc(size);
4380 xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
4381 "xmlTextWriterVSprintf : out of memory!\n");
4385 VA_COPY(locarg, argptr);
4386 while (((count = vsnprintf((char *) buf, size, format, locarg)) < 0)
4387 || (count == size - 1) || (count == size) || (count > size)) {
4391 buf = (xmlChar *) xmlMalloc(size);
4393 xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
4394 "xmlTextWriterVSprintf : out of memory!\n");
4397 VA_COPY(locarg, argptr);
4405 * xmlTextWriterStartDocumentCallback:
4406 * @ctx: the user data (XML parser context)
4408 * called at the start of document processing.
4411 xmlTextWriterStartDocumentCallback(void *ctx)
4413 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
4417 #ifdef LIBXML_HTML_ENABLED
4418 if (ctxt->myDoc == NULL)
4419 ctxt->myDoc = htmlNewDocNoDtD(NULL, NULL);
4420 if (ctxt->myDoc == NULL) {
4421 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4422 ctxt->sax->error(ctxt->userData,
4423 "SAX.startDocument(): out of memory\n");
4424 ctxt->errNo = XML_ERR_NO_MEMORY;
4425 ctxt->instate = XML_PARSER_EOF;
4426 ctxt->disableSAX = 1;
4430 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
4431 "libxml2 built without HTML support\n");
4432 ctxt->errNo = XML_ERR_INTERNAL_ERROR;
4433 ctxt->instate = XML_PARSER_EOF;
4434 ctxt->disableSAX = 1;
4440 doc = ctxt->myDoc = xmlNewDoc(ctxt->version);
4442 if (doc->children == NULL) {
4443 if (ctxt->encoding != NULL)
4444 doc->encoding = xmlStrdup(ctxt->encoding);
4446 doc->encoding = NULL;
4447 doc->standalone = ctxt->standalone;
4450 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4451 ctxt->sax->error(ctxt->userData,
4452 "SAX.startDocument(): out of memory\n");
4453 ctxt->errNo = XML_ERR_NO_MEMORY;
4454 ctxt->instate = XML_PARSER_EOF;
4455 ctxt->disableSAX = 1;
4459 if ((ctxt->myDoc != NULL) && (ctxt->myDoc->URL == NULL) &&
4460 (ctxt->input != NULL) && (ctxt->input->filename != NULL)) {
4462 xmlCanonicPath((const xmlChar *) ctxt->input->filename);
4463 if (ctxt->myDoc->URL == NULL)
4465 xmlStrdup((const xmlChar *) ctxt->input->filename);
4470 * xmlTextWriterSetIndent:
4471 * @writer: the xmlTextWriterPtr
4472 * @indent: do indentation?
4474 * Set indentation output. indent = 0 do not indentation. indent > 0 do indentation.
4476 * Returns -1 on error or 0 otherwise.
4479 xmlTextWriterSetIndent(xmlTextWriterPtr writer, int indent)
4481 if ((writer == NULL) || (indent < 0))
4484 writer->indent = indent;
4485 writer->doindent = 1;
4491 * xmlTextWriterSetIndentString:
4492 * @writer: the xmlTextWriterPtr
4493 * @str: the xmlChar string
4495 * Set string indentation.
4497 * Returns -1 on error or 0 otherwise.
4500 xmlTextWriterSetIndentString(xmlTextWriterPtr writer, const xmlChar * str)
4502 if ((writer == NULL) || (!str))
4505 if (writer->ichar != NULL)
4506 xmlFree(writer->ichar);
4507 writer->ichar = xmlStrdup(str);
4516 * xmlTextWriterWriteIndent:
4517 * @writer: the xmlTextWriterPtr
4519 * Write indent string.
4521 * Returns -1 on error or the number of strings written.
4524 xmlTextWriterWriteIndent(xmlTextWriterPtr writer)
4530 lksize = xmlListSize(writer->nodes);
4532 return (-1); /* list is empty */
4533 for (i = 0; i < (lksize - 1); i++) {
4534 ret = xmlOutputBufferWriteString(writer->out,
4535 (const char *) writer->ichar);
4540 return (lksize - 1);
4544 * xmlTextWriterHandleStateDependencies:
4545 * @writer: the xmlTextWriterPtr
4546 * @p: the xmlTextWriterStackEntry
4548 * Write state dependent strings.
4550 * Returns -1 on error or the number of characters written.
4553 xmlTextWriterHandleStateDependencies(xmlTextWriterPtr writer,
4554 xmlTextWriterStackEntry * p)
4567 extra[0] = extra[1] = extra[2] = '\0';
4571 case XML_TEXTWRITER_NAME:
4573 p->state = XML_TEXTWRITER_TEXT;
4575 case XML_TEXTWRITER_PI:
4577 p->state = XML_TEXTWRITER_PI_TEXT;
4579 case XML_TEXTWRITER_DTD:
4582 p->state = XML_TEXTWRITER_DTD_TEXT;
4584 case XML_TEXTWRITER_DTD_ELEM:
4586 p->state = XML_TEXTWRITER_DTD_ELEM_TEXT;
4588 case XML_TEXTWRITER_DTD_ATTL:
4590 p->state = XML_TEXTWRITER_DTD_ATTL_TEXT;
4592 case XML_TEXTWRITER_DTD_ENTY:
4593 case XML_TEXTWRITER_DTD_PENT:
4595 extra[1] = writer->qchar;
4596 p->state = XML_TEXTWRITER_DTD_ENTY_TEXT;
4603 if (*extra != '\0') {
4604 count = xmlOutputBufferWriteString(writer->out, extra);
4613 #define bottom_xmlwriter
4614 #include "elfgcchack.h"