3 * xmlwriter.c: XML text writer implementation
5 * For license and disclaimer see the license and disclaimer of
15 #include <libxml/xmlmemory.h>
16 #include <libxml/parser.h>
17 #include <libxml/uri.h>
18 #include <libxml/HTMLtree.h>
20 #ifdef LIBXML_WRITER_ENABLED
22 #include <libxml/xmlwriter.h>
25 #define B64CRLF "\r\n"
28 * The following VA_COPY was coded following an example in
29 * the Samba project. It may not be sufficient for some
30 * esoteric implementations of va_list (i.e. it may need
31 * something involving a memcpy) but (hopefully) will be
32 * sufficient for libxml2.
36 #define VA_COPY(dest, src) va_copy(dest, src)
39 #define VA_COPY(dest,src) __va_copy(dest, src)
41 #define VA_COPY(dest,src) (dest) = (src)
47 * Types are kept private
50 XML_TEXTWRITER_NONE = 0,
52 XML_TEXTWRITER_ATTRIBUTE,
55 XML_TEXTWRITER_PI_TEXT,
58 XML_TEXTWRITER_DTD_TEXT,
59 XML_TEXTWRITER_DTD_ELEM,
60 XML_TEXTWRITER_DTD_ELEM_TEXT,
61 XML_TEXTWRITER_DTD_ATTL,
62 XML_TEXTWRITER_DTD_ATTL_TEXT,
63 XML_TEXTWRITER_DTD_ENTY, /* entity */
64 XML_TEXTWRITER_DTD_ENTY_TEXT,
65 XML_TEXTWRITER_DTD_PENT, /* parameter entity */
66 XML_TEXTWRITER_COMMENT
69 typedef struct _xmlTextWriterStackEntry xmlTextWriterStackEntry;
71 struct _xmlTextWriterStackEntry {
73 xmlTextWriterState state;
76 typedef struct _xmlTextWriterNsStackEntry xmlTextWriterNsStackEntry;
77 struct _xmlTextWriterNsStackEntry {
83 struct _xmlTextWriter {
84 xmlOutputBufferPtr out; /* output buffer */
85 xmlListPtr nodes; /* element name stack */
86 xmlListPtr nsstack; /* name spaces stack */
88 int indent; /* enable indent */
89 int doindent; /* internal indent flag */
90 xmlChar *ichar; /* indent character */
91 char qchar; /* character used for quoting attribute values */
92 xmlParserCtxtPtr ctxt;
97 static void xmlFreeTextWriterStackEntry(xmlLinkPtr lk);
98 static int xmlCmpTextWriterStackEntry(const void *data0,
100 static int xmlTextWriterOutputNSDecl(xmlTextWriterPtr writer);
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, "%s", msg);
134 __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_WRITER, error,
135 XML_ERR_FATAL, NULL, 0, NULL, NULL, NULL, 0, 0, "%s", 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_IO_EIO,
246 "xmlNewTextWriterFilename : cannot open uri\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 xmlFreeDoc(ctxt->myDoc);
393 xmlFreeParserCtxt(ctxt);
394 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
395 "xmlNewTextWriterDoc : error at xmlNewTextWriterPushParser!\n");
399 xmlSetDocCompressMode(ctxt->myDoc, compression);
403 ret->no_doc_free = 1;
410 * xmlNewTextWriterTree:
412 * @node: xmlNodePtr or NULL for doc->children
413 * @compression: compress the output?
415 * Create a new xmlNewTextWriter structure with @doc as output
418 * Returns the new xmlTextWriterPtr or NULL in case of error
421 xmlNewTextWriterTree(xmlDocPtr doc, xmlNodePtr node, int compression)
423 xmlTextWriterPtr ret;
424 xmlSAXHandler saxHandler;
425 xmlParserCtxtPtr ctxt;
428 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
429 "xmlNewTextWriterTree : invalid document tree!\n");
433 memset(&saxHandler, '\0', sizeof(saxHandler));
434 xmlSAX2InitDefaultSAXHandler(&saxHandler, 1);
435 saxHandler.startDocument = xmlTextWriterStartDocumentCallback;
436 saxHandler.startElement = xmlSAX2StartElement;
437 saxHandler.endElement = xmlSAX2EndElement;
439 ctxt = xmlCreatePushParserCtxt(&saxHandler, NULL, NULL, 0, NULL);
441 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
442 "xmlNewTextWriterDoc : error at xmlCreatePushParserCtxt!\n");
446 * For some reason this seems to completely break if node names
451 ret = xmlNewTextWriterPushParser(ctxt, compression);
453 xmlFreeParserCtxt(ctxt);
454 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
455 "xmlNewTextWriterDoc : error at xmlNewTextWriterPushParser!\n");
461 ret->no_doc_free = 1;
463 xmlSetDocCompressMode(doc, compression);
470 * @writer: the xmlTextWriterPtr
472 * Deallocate all the resources associated to the writer
475 xmlFreeTextWriter(xmlTextWriterPtr writer)
480 if (writer->out != NULL)
481 xmlOutputBufferClose(writer->out);
483 if (writer->nodes != NULL)
484 xmlListDelete(writer->nodes);
486 if (writer->nsstack != NULL)
487 xmlListDelete(writer->nsstack);
489 if (writer->ctxt != NULL) {
490 if ((writer->ctxt->myDoc != NULL) && (writer->no_doc_free == 0)) {
491 xmlFreeDoc(writer->ctxt->myDoc);
492 writer->ctxt->myDoc = NULL;
494 xmlFreeParserCtxt(writer->ctxt);
497 if (writer->doc != NULL)
498 xmlFreeDoc(writer->doc);
500 if (writer->ichar != NULL)
501 xmlFree(writer->ichar);
506 * xmlTextWriterStartDocument:
507 * @writer: the xmlTextWriterPtr
508 * @version: the xml version ("1.0") or NULL for default ("1.0")
509 * @encoding: the encoding or NULL for default
510 * @standalone: "yes" or "no" or NULL for default
512 * Start a new xml document
514 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
517 xmlTextWriterStartDocument(xmlTextWriterPtr writer, const char *version,
518 const char *encoding, const char *standalone)
523 xmlCharEncodingHandlerPtr encoder;
525 if ((writer == NULL) || (writer->out == NULL)) {
526 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
527 "xmlTextWriterStartDocument : invalid writer!\n");
531 lk = xmlListFront(writer->nodes);
532 if ((lk != NULL) && (xmlLinkGetData(lk) != NULL)) {
533 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
534 "xmlTextWriterStartDocument : not allowed in this context!\n");
539 if (encoding != NULL) {
540 encoder = xmlFindCharEncodingHandler(encoding);
541 if (encoder == NULL) {
542 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
543 "xmlTextWriterStartDocument : out of memory!\n");
548 writer->out->encoder = encoder;
549 if (encoder != NULL) {
550 if (writer->out->conv == NULL) {
551 writer->out->conv = xmlBufferCreateSize(4000);
553 xmlCharEncOutFunc(encoder, writer->out->conv, NULL);
554 if ((writer->doc != NULL) && (writer->doc->encoding == NULL))
555 writer->doc->encoding = xmlStrdup((xmlChar *)writer->out->encoder->name);
557 writer->out->conv = NULL;
560 count = xmlOutputBufferWriteString(writer->out, "<?xml version=");
564 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
569 count = xmlOutputBufferWriteString(writer->out, version);
571 count = xmlOutputBufferWriteString(writer->out, "1.0");
575 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
579 if (writer->out->encoder != 0) {
580 count = xmlOutputBufferWriteString(writer->out, " encoding=");
584 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
589 xmlOutputBufferWriteString(writer->out,
590 writer->out->encoder->name);
594 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
600 if (standalone != 0) {
601 count = xmlOutputBufferWriteString(writer->out, " standalone=");
605 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
609 count = xmlOutputBufferWriteString(writer->out, standalone);
613 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
619 count = xmlOutputBufferWriteString(writer->out, "?>\n");
628 * xmlTextWriterEndDocument:
629 * @writer: the xmlTextWriterPtr
631 * End an xml document. All open elements are closed, and
632 * the content is flushed to the output.
634 * Returns the bytes written or -1 in case of error
637 xmlTextWriterEndDocument(xmlTextWriterPtr writer)
642 xmlTextWriterStackEntry *p;
644 if (writer == NULL) {
645 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
646 "xmlTextWriterEndDocument : invalid writer!\n");
651 while ((lk = xmlListFront(writer->nodes)) != NULL) {
652 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
656 case XML_TEXTWRITER_NAME:
657 case XML_TEXTWRITER_ATTRIBUTE:
658 case XML_TEXTWRITER_TEXT:
659 count = xmlTextWriterEndElement(writer);
664 case XML_TEXTWRITER_PI:
665 case XML_TEXTWRITER_PI_TEXT:
666 count = xmlTextWriterEndPI(writer);
671 case XML_TEXTWRITER_CDATA:
672 count = xmlTextWriterEndCDATA(writer);
677 case XML_TEXTWRITER_DTD:
678 case XML_TEXTWRITER_DTD_TEXT:
679 case XML_TEXTWRITER_DTD_ELEM:
680 case XML_TEXTWRITER_DTD_ELEM_TEXT:
681 case XML_TEXTWRITER_DTD_ATTL:
682 case XML_TEXTWRITER_DTD_ATTL_TEXT:
683 case XML_TEXTWRITER_DTD_ENTY:
684 case XML_TEXTWRITER_DTD_ENTY_TEXT:
685 case XML_TEXTWRITER_DTD_PENT:
686 count = xmlTextWriterEndDTD(writer);
691 case XML_TEXTWRITER_COMMENT:
692 count = xmlTextWriterEndComment(writer);
702 if (!writer->indent) {
703 count = xmlOutputBufferWriteString(writer->out, "\n");
709 sum += xmlTextWriterFlush(writer);
715 * xmlTextWriterStartComment:
716 * @writer: the xmlTextWriterPtr
718 * Start an xml comment.
720 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
723 xmlTextWriterStartComment(xmlTextWriterPtr writer)
728 xmlTextWriterStackEntry *p;
730 if (writer == NULL) {
731 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
732 "xmlTextWriterStartComment : invalid writer!\n");
737 lk = xmlListFront(writer->nodes);
739 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
742 case XML_TEXTWRITER_TEXT:
743 case XML_TEXTWRITER_NONE:
745 case XML_TEXTWRITER_NAME:
746 /* Output namespace declarations */
747 count = xmlTextWriterOutputNSDecl(writer);
751 count = xmlOutputBufferWriteString(writer->out, ">");
755 if (writer->indent) {
757 xmlOutputBufferWriteString(writer->out, "\n");
762 p->state = XML_TEXTWRITER_TEXT;
770 p = (xmlTextWriterStackEntry *)
771 xmlMalloc(sizeof(xmlTextWriterStackEntry));
773 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
774 "xmlTextWriterStartElement : out of memory!\n");
779 p->state = XML_TEXTWRITER_COMMENT;
781 xmlListPushFront(writer->nodes, p);
783 if (writer->indent) {
784 count = xmlTextWriterWriteIndent(writer);
790 count = xmlOutputBufferWriteString(writer->out, "<!--");
799 * xmlTextWriterEndComment:
800 * @writer: the xmlTextWriterPtr
802 * End the current xml coment.
804 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
807 xmlTextWriterEndComment(xmlTextWriterPtr writer)
812 xmlTextWriterStackEntry *p;
814 if (writer == NULL) {
815 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
816 "xmlTextWriterEndComment : invalid writer!\n");
820 lk = xmlListFront(writer->nodes);
822 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
823 "xmlTextWriterEndComment : not allowed in this context!\n");
827 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
833 case XML_TEXTWRITER_COMMENT:
834 count = xmlOutputBufferWriteString(writer->out, "-->");
843 if (writer->indent) {
844 count = xmlOutputBufferWriteString(writer->out, "\n");
850 xmlListPopFront(writer->nodes);
855 * xmlTextWriterWriteFormatComment:
856 * @writer: the xmlTextWriterPtr
857 * @format: format string (see printf)
858 * @...: extra parameters for the format
860 * Write an xml comment.
862 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
865 xmlTextWriterWriteFormatComment(xmlTextWriterPtr writer,
866 const char *format, ...)
871 va_start(ap, format);
873 rc = xmlTextWriterWriteVFormatComment(writer, format, ap);
880 * xmlTextWriterWriteVFormatComment:
881 * @writer: the xmlTextWriterPtr
882 * @format: format string (see printf)
883 * @argptr: pointer to the first member of the variable argument list.
885 * Write an xml comment.
887 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
890 xmlTextWriterWriteVFormatComment(xmlTextWriterPtr writer,
891 const char *format, va_list argptr)
896 if (writer == NULL) {
897 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
898 "xmlTextWriterWriteVFormatComment : invalid writer!\n");
902 buf = xmlTextWriterVSprintf(format, argptr);
906 rc = xmlTextWriterWriteComment(writer, buf);
913 * xmlTextWriterWriteComment:
914 * @writer: the xmlTextWriterPtr
915 * @content: comment string
917 * Write an xml comment.
919 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
922 xmlTextWriterWriteComment(xmlTextWriterPtr writer, const xmlChar * content)
928 count = xmlTextWriterStartComment(writer);
932 count = xmlTextWriterWriteString(writer, content);
936 count = xmlTextWriterEndComment(writer);
945 * xmlTextWriterStartElement:
946 * @writer: the xmlTextWriterPtr
947 * @name: element name
949 * Start an xml element.
951 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
954 xmlTextWriterStartElement(xmlTextWriterPtr writer, const xmlChar * name)
959 xmlTextWriterStackEntry *p;
961 if ((writer == NULL) || (name == NULL) || (*name == '\0'))
965 lk = xmlListFront(writer->nodes);
967 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
970 case XML_TEXTWRITER_PI:
971 case XML_TEXTWRITER_PI_TEXT:
973 case XML_TEXTWRITER_NONE:
975 case XML_TEXTWRITER_ATTRIBUTE:
976 count = xmlTextWriterEndAttribute(writer);
981 case XML_TEXTWRITER_NAME:
982 /* Output namespace declarations */
983 count = xmlTextWriterOutputNSDecl(writer);
987 count = xmlOutputBufferWriteString(writer->out, ">");
993 xmlOutputBufferWriteString(writer->out, "\n");
994 p->state = XML_TEXTWRITER_TEXT;
1002 p = (xmlTextWriterStackEntry *)
1003 xmlMalloc(sizeof(xmlTextWriterStackEntry));
1005 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
1006 "xmlTextWriterStartElement : out of memory!\n");
1010 p->name = xmlStrdup(name);
1012 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
1013 "xmlTextWriterStartElement : out of memory!\n");
1017 p->state = XML_TEXTWRITER_NAME;
1019 xmlListPushFront(writer->nodes, p);
1021 if (writer->indent) {
1022 count = xmlTextWriterWriteIndent(writer);
1026 count = xmlOutputBufferWriteString(writer->out, "<");
1031 xmlOutputBufferWriteString(writer->out, (const char *) p->name);
1040 * xmlTextWriterStartElementNS:
1041 * @writer: the xmlTextWriterPtr
1042 * @prefix: namespace prefix or NULL
1043 * @name: element local name
1044 * @namespaceURI: namespace URI or NULL
1046 * Start an xml element with namespace support.
1048 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1051 xmlTextWriterStartElementNS(xmlTextWriterPtr writer,
1052 const xmlChar * prefix, const xmlChar * name,
1053 const xmlChar * namespaceURI)
1059 if ((writer == NULL) || (name == NULL) || (*name == '\0'))
1064 buf = xmlStrdup(prefix);
1065 buf = xmlStrcat(buf, BAD_CAST ":");
1067 buf = xmlStrcat(buf, name);
1070 count = xmlTextWriterStartElement(writer, buf);
1076 if (namespaceURI != 0) {
1077 xmlTextWriterNsStackEntry *p = (xmlTextWriterNsStackEntry *)
1078 xmlMalloc(sizeof(xmlTextWriterNsStackEntry));
1080 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
1081 "xmlTextWriterStartElementNS : out of memory!\n");
1085 buf = xmlStrdup(BAD_CAST "xmlns");
1087 buf = xmlStrcat(buf, BAD_CAST ":");
1088 buf = xmlStrcat(buf, prefix);
1092 p->uri = xmlStrdup(namespaceURI);
1094 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
1095 "xmlTextWriterStartElementNS : out of memory!\n");
1099 p->elem = xmlListFront(writer->nodes);
1101 xmlListPushFront(writer->nsstack, p);
1108 * xmlTextWriterEndElement:
1109 * @writer: the xmlTextWriterPtr
1111 * End the current xml element.
1113 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1116 xmlTextWriterEndElement(xmlTextWriterPtr writer)
1121 xmlTextWriterStackEntry *p;
1126 lk = xmlListFront(writer->nodes);
1128 xmlListDelete(writer->nsstack);
1129 writer->nsstack = NULL;
1133 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1135 xmlListDelete(writer->nsstack);
1136 writer->nsstack = NULL;
1142 case XML_TEXTWRITER_ATTRIBUTE:
1143 count = xmlTextWriterEndAttribute(writer);
1145 xmlListDelete(writer->nsstack);
1146 writer->nsstack = NULL;
1151 case XML_TEXTWRITER_NAME:
1152 /* Output namespace declarations */
1153 count = xmlTextWriterOutputNSDecl(writer);
1158 if (writer->indent) /* next element needs indent */
1159 writer->doindent = 1;
1160 count = xmlOutputBufferWriteString(writer->out, "/>");
1165 case XML_TEXTWRITER_TEXT:
1166 if ((writer->indent) && (writer->doindent)) {
1167 count = xmlTextWriterWriteIndent(writer);
1169 writer->doindent = 1;
1171 writer->doindent = 1;
1172 count = xmlOutputBufferWriteString(writer->out, "</");
1176 count = xmlOutputBufferWriteString(writer->out,
1177 (const char *) p->name);
1181 count = xmlOutputBufferWriteString(writer->out, ">");
1190 if (writer->indent) {
1191 count = xmlOutputBufferWriteString(writer->out, "\n");
1195 xmlListPopFront(writer->nodes);
1200 * xmlTextWriterFullEndElement:
1201 * @writer: the xmlTextWriterPtr
1203 * End the current xml element. Writes an end tag even if the element is empty
1205 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1208 xmlTextWriterFullEndElement(xmlTextWriterPtr writer)
1213 xmlTextWriterStackEntry *p;
1218 lk = xmlListFront(writer->nodes);
1222 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1228 case XML_TEXTWRITER_ATTRIBUTE:
1229 count = xmlTextWriterEndAttribute(writer);
1234 case XML_TEXTWRITER_NAME:
1235 /* Output namespace declarations */
1236 count = xmlTextWriterOutputNSDecl(writer);
1241 count = xmlOutputBufferWriteString(writer->out, ">");
1246 writer->doindent = 0;
1248 case XML_TEXTWRITER_TEXT:
1249 if ((writer->indent) && (writer->doindent)) {
1250 count = xmlTextWriterWriteIndent(writer);
1252 writer->doindent = 1;
1254 writer->doindent = 1;
1255 count = xmlOutputBufferWriteString(writer->out, "</");
1259 count = xmlOutputBufferWriteString(writer->out,
1260 (const char *) p->name);
1264 count = xmlOutputBufferWriteString(writer->out, ">");
1273 if (writer->indent) {
1274 count = xmlOutputBufferWriteString(writer->out, "\n");
1278 xmlListPopFront(writer->nodes);
1283 * xmlTextWriterWriteFormatRaw:
1284 * @writer: the xmlTextWriterPtr
1285 * @format: format string (see printf)
1286 * @...: extra parameters for the format
1288 * Write a formatted raw xml text.
1290 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1293 xmlTextWriterWriteFormatRaw(xmlTextWriterPtr writer, const char *format,
1299 va_start(ap, format);
1301 rc = xmlTextWriterWriteVFormatRaw(writer, format, ap);
1308 * xmlTextWriterWriteVFormatRaw:
1309 * @writer: the xmlTextWriterPtr
1310 * @format: format string (see printf)
1311 * @argptr: pointer to the first member of the variable argument list.
1313 * Write a formatted raw xml text.
1315 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1318 xmlTextWriterWriteVFormatRaw(xmlTextWriterPtr writer, const char *format,
1327 buf = xmlTextWriterVSprintf(format, argptr);
1331 rc = xmlTextWriterWriteRaw(writer, buf);
1338 * xmlTextWriterWriteRawLen:
1339 * @writer: the xmlTextWriterPtr
1340 * @content: text string
1341 * @len: length of the text string
1343 * Write an xml text.
1344 * TODO: what about entities and special chars??
1346 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1349 xmlTextWriterWriteRawLen(xmlTextWriterPtr writer, const xmlChar * content,
1355 xmlTextWriterStackEntry *p;
1357 if (writer == NULL) {
1358 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
1359 "xmlTextWriterWriteRawLen : invalid writer!\n");
1363 if ((content == NULL) || (len < 0)) {
1364 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
1365 "xmlTextWriterWriteRawLen : invalid content!\n");
1370 lk = xmlListFront(writer->nodes);
1372 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1373 count = xmlTextWriterHandleStateDependencies(writer, p);
1380 writer->doindent = 0;
1382 if (content != NULL) {
1384 xmlOutputBufferWrite(writer->out, len, (const char *) content);
1394 * xmlTextWriterWriteRaw:
1395 * @writer: the xmlTextWriterPtr
1396 * @content: text string
1398 * Write a raw xml text.
1400 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1403 xmlTextWriterWriteRaw(xmlTextWriterPtr writer, const xmlChar * content)
1405 return xmlTextWriterWriteRawLen(writer, content, xmlStrlen(content));
1409 * xmlTextWriterWriteFormatString:
1410 * @writer: the xmlTextWriterPtr
1411 * @format: format string (see printf)
1412 * @...: extra parameters for the format
1414 * Write a formatted xml text.
1416 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1419 xmlTextWriterWriteFormatString(xmlTextWriterPtr writer, const char *format,
1425 if ((writer == NULL) || (format == NULL))
1428 va_start(ap, format);
1430 rc = xmlTextWriterWriteVFormatString(writer, format, ap);
1437 * xmlTextWriterWriteVFormatString:
1438 * @writer: the xmlTextWriterPtr
1439 * @format: format string (see printf)
1440 * @argptr: pointer to the first member of the variable argument list.
1442 * Write a formatted xml text.
1444 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1447 xmlTextWriterWriteVFormatString(xmlTextWriterPtr writer,
1448 const char *format, va_list argptr)
1453 if ((writer == NULL) || (format == NULL))
1456 buf = xmlTextWriterVSprintf(format, argptr);
1460 rc = xmlTextWriterWriteString(writer, buf);
1467 * xmlTextWriterWriteString:
1468 * @writer: the xmlTextWriterPtr
1469 * @content: text string
1471 * Write an xml text.
1473 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1476 xmlTextWriterWriteString(xmlTextWriterPtr writer, const xmlChar * content)
1481 xmlTextWriterStackEntry *p;
1484 if ((writer == NULL) || (content == NULL))
1488 buf = (xmlChar *) content;
1489 lk = xmlListFront(writer->nodes);
1491 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1494 case XML_TEXTWRITER_NAME:
1495 case XML_TEXTWRITER_TEXT:
1498 xmlOutputBufferWriteEscape(writer->out, content, NULL);
1500 buf = xmlEncodeSpecialChars(NULL, content);
1502 case XML_TEXTWRITER_ATTRIBUTE:
1504 xmlAttrSerializeTxtContent(writer->out->buffer, writer->doc,
1514 count = xmlTextWriterWriteRaw(writer, buf);
1516 if (buf != content) /* buf was allocated by us, so free it */
1528 * xmlOutputBufferWriteBase64:
1529 * @out: the xmlOutputBufferPtr
1530 * @data: binary data
1531 * @len: the number of bytes to encode
1533 * Write base64 encoded data to an xmlOutputBuffer.
1534 * Adapted from John Walker's base64.c (http://www.fourmilab.ch/).
1536 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1539 xmlOutputBufferWriteBase64(xmlOutputBufferPtr out, int len,
1540 const unsigned char *data)
1542 static unsigned char dtable[64] =
1543 {'A','B','C','D','E','F','G','H','I','J','K','L','M',
1544 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
1545 'a','b','c','d','e','f','g','h','i','j','k','l','m',
1546 'n','o','p','q','r','s','t','u','v','w','x','y','z',
1547 '0','1','2','3','4','5','6','7','8','9','+','/'};
1554 if ((out == NULL) || (len < 0) || (data == NULL))
1562 unsigned char igroup[3];
1563 unsigned char ogroup[4];
1567 igroup[0] = igroup[1] = igroup[2] = 0;
1568 for (n = 0; n < 3 && i < len; n++, i++) {
1570 igroup[n] = (unsigned char) c;
1574 ogroup[0] = dtable[igroup[0] >> 2];
1575 ogroup[1] = dtable[((igroup[0] & 3) << 4) | (igroup[1] >> 4)];
1577 dtable[((igroup[1] & 0xF) << 2) | (igroup[2] >> 6)];
1578 ogroup[3] = dtable[igroup[2] & 0x3F];
1587 if (linelen >= B64LINELEN) {
1588 count = xmlOutputBufferWrite(out, 2, B64CRLF);
1594 count = xmlOutputBufferWrite(out, 4, (const char *) ogroup);
1610 * xmlTextWriterWriteBase64:
1611 * @writer: the xmlTextWriterPtr
1612 * @data: binary data
1613 * @start: the position within the data of the first byte to encode
1614 * @len: the number of bytes to encode
1616 * Write an base64 encoded xml text.
1618 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1621 xmlTextWriterWriteBase64(xmlTextWriterPtr writer, const char *data,
1627 xmlTextWriterStackEntry *p;
1629 if ((writer == NULL) || (data == NULL) || (start < 0) || (len < 0))
1633 lk = xmlListFront(writer->nodes);
1635 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1637 count = xmlTextWriterHandleStateDependencies(writer, p);
1645 writer->doindent = 0;
1648 xmlOutputBufferWriteBase64(writer->out, len,
1649 (unsigned char *) data + start);
1658 * xmlOutputBufferWriteBinHex:
1659 * @out: the xmlOutputBufferPtr
1660 * @data: binary data
1661 * @len: the number of bytes to encode
1663 * Write hqx encoded data to an xmlOutputBuffer.
1666 * Returns the bytes written (may be 0 because of buffering)
1667 * or -1 in case of error
1670 xmlOutputBufferWriteBinHex(xmlOutputBufferPtr out,
1671 int len, const unsigned char *data)
1675 static char hex[16] =
1676 {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
1679 if ((out == NULL) || (data == NULL) || (len < 0)) {
1684 for (i = 0; i < len; i++) {
1686 xmlOutputBufferWrite(out, 1,
1687 (const char *) &hex[data[i] >> 4]);
1692 xmlOutputBufferWrite(out, 1,
1693 (const char *) &hex[data[i] & 0xF]);
1703 * xmlTextWriterWriteBinHex:
1704 * @writer: the xmlTextWriterPtr
1705 * @data: binary data
1706 * @start: the position within the data of the first byte to encode
1707 * @len: the number of bytes to encode
1709 * Write a BinHex encoded xml text.
1711 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1714 xmlTextWriterWriteBinHex(xmlTextWriterPtr writer, const char *data,
1720 xmlTextWriterStackEntry *p;
1722 if ((writer == NULL) || (data == NULL) || (start < 0) || (len < 0))
1726 lk = xmlListFront(writer->nodes);
1728 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1730 count = xmlTextWriterHandleStateDependencies(writer, p);
1738 writer->doindent = 0;
1741 xmlOutputBufferWriteBinHex(writer->out, len,
1742 (unsigned char *) data + start);
1751 * xmlTextWriterStartAttribute:
1752 * @writer: the xmlTextWriterPtr
1753 * @name: element name
1755 * Start an xml attribute.
1757 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1760 xmlTextWriterStartAttribute(xmlTextWriterPtr writer, const xmlChar * name)
1765 xmlTextWriterStackEntry *p;
1767 if ((writer == NULL) || (name == NULL) || (*name == '\0'))
1771 lk = xmlListFront(writer->nodes);
1775 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1780 case XML_TEXTWRITER_ATTRIBUTE:
1781 count = xmlTextWriterEndAttribute(writer);
1786 case XML_TEXTWRITER_NAME:
1787 count = xmlOutputBufferWriteString(writer->out, " ");
1792 xmlOutputBufferWriteString(writer->out,
1793 (const char *) name);
1797 count = xmlOutputBufferWriteString(writer->out, "=");
1801 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
1805 p->state = XML_TEXTWRITER_ATTRIBUTE;
1815 * xmlTextWriterStartAttributeNS:
1816 * @writer: the xmlTextWriterPtr
1817 * @prefix: namespace prefix or NULL
1818 * @name: element local name
1819 * @namespaceURI: namespace URI or NULL
1821 * Start an xml attribute with namespace support.
1823 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1826 xmlTextWriterStartAttributeNS(xmlTextWriterPtr writer,
1827 const xmlChar * prefix, const xmlChar * name,
1828 const xmlChar * namespaceURI)
1833 xmlTextWriterNsStackEntry *p;
1835 if ((writer == NULL) || (name == NULL) || (*name == '\0'))
1838 /* Handle namespace first in case of error */
1839 if (namespaceURI != 0) {
1840 xmlTextWriterNsStackEntry nsentry, *curns;
1842 buf = xmlStrdup(BAD_CAST "xmlns");
1844 buf = xmlStrcat(buf, BAD_CAST ":");
1845 buf = xmlStrcat(buf, prefix);
1848 nsentry.prefix = buf;
1849 nsentry.uri = (xmlChar *)namespaceURI;
1850 nsentry.elem = xmlListFront(writer->nodes);
1852 curns = (xmlTextWriterNsStackEntry *)xmlListSearch(writer->nsstack,
1854 if ((curns != NULL)) {
1856 if (xmlStrcmp(curns->uri, namespaceURI) == 0) {
1857 /* Namespace already defined on element skip */
1860 /* Prefix mismatch so error out */
1865 /* Do not add namespace decl to list - it is already there */
1867 p = (xmlTextWriterNsStackEntry *)
1868 xmlMalloc(sizeof(xmlTextWriterNsStackEntry));
1870 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
1871 "xmlTextWriterStartAttributeNS : out of memory!\n");
1876 p->uri = xmlStrdup(namespaceURI);
1878 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
1879 "xmlTextWriterStartAttributeNS : out of memory!\n");
1883 p->elem = xmlListFront(writer->nodes);
1885 xmlListPushFront(writer->nsstack, p);
1891 buf = xmlStrdup(prefix);
1892 buf = xmlStrcat(buf, BAD_CAST ":");
1894 buf = xmlStrcat(buf, name);
1897 count = xmlTextWriterStartAttribute(writer, buf);
1907 * xmlTextWriterEndAttribute:
1908 * @writer: the xmlTextWriterPtr
1910 * End the current xml element.
1912 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1915 xmlTextWriterEndAttribute(xmlTextWriterPtr writer)
1920 xmlTextWriterStackEntry *p;
1925 lk = xmlListFront(writer->nodes);
1930 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1937 case XML_TEXTWRITER_ATTRIBUTE:
1938 p->state = XML_TEXTWRITER_NAME;
1940 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
1954 * xmlTextWriterWriteFormatAttribute:
1955 * @writer: the xmlTextWriterPtr
1956 * @name: attribute name
1957 * @format: format string (see printf)
1958 * @...: extra parameters for the format
1960 * Write a formatted xml attribute.
1962 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1965 xmlTextWriterWriteFormatAttribute(xmlTextWriterPtr writer,
1966 const xmlChar * name, const char *format,
1972 va_start(ap, format);
1974 rc = xmlTextWriterWriteVFormatAttribute(writer, name, format, ap);
1981 * xmlTextWriterWriteVFormatAttribute:
1982 * @writer: the xmlTextWriterPtr
1983 * @name: attribute name
1984 * @format: format string (see printf)
1985 * @argptr: pointer to the first member of the variable argument list.
1987 * Write a formatted xml attribute.
1989 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1992 xmlTextWriterWriteVFormatAttribute(xmlTextWriterPtr writer,
1993 const xmlChar * name,
1994 const char *format, va_list argptr)
2002 buf = xmlTextWriterVSprintf(format, argptr);
2006 rc = xmlTextWriterWriteAttribute(writer, name, buf);
2013 * xmlTextWriterWriteAttribute:
2014 * @writer: the xmlTextWriterPtr
2015 * @name: attribute name
2016 * @content: attribute content
2018 * Write an xml attribute.
2020 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2023 xmlTextWriterWriteAttribute(xmlTextWriterPtr writer, const xmlChar * name,
2024 const xmlChar * content)
2030 count = xmlTextWriterStartAttribute(writer, name);
2034 count = xmlTextWriterWriteString(writer, content);
2038 count = xmlTextWriterEndAttribute(writer);
2047 * xmlTextWriterWriteFormatAttributeNS:
2048 * @writer: the xmlTextWriterPtr
2049 * @prefix: namespace prefix
2050 * @name: attribute local name
2051 * @namespaceURI: namespace URI
2052 * @format: format string (see printf)
2053 * @...: extra parameters for the format
2055 * Write a formatted xml attribute.with namespace support
2057 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2060 xmlTextWriterWriteFormatAttributeNS(xmlTextWriterPtr writer,
2061 const xmlChar * prefix,
2062 const xmlChar * name,
2063 const xmlChar * namespaceURI,
2064 const char *format, ...)
2069 va_start(ap, format);
2071 rc = xmlTextWriterWriteVFormatAttributeNS(writer, prefix, name,
2072 namespaceURI, format, ap);
2079 * xmlTextWriterWriteVFormatAttributeNS:
2080 * @writer: the xmlTextWriterPtr
2081 * @prefix: namespace prefix
2082 * @name: attribute local name
2083 * @namespaceURI: namespace URI
2084 * @format: format string (see printf)
2085 * @argptr: pointer to the first member of the variable argument list.
2087 * Write a formatted xml attribute.with namespace support
2089 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2092 xmlTextWriterWriteVFormatAttributeNS(xmlTextWriterPtr writer,
2093 const xmlChar * prefix,
2094 const xmlChar * name,
2095 const xmlChar * namespaceURI,
2096 const char *format, va_list argptr)
2104 buf = xmlTextWriterVSprintf(format, argptr);
2108 rc = xmlTextWriterWriteAttributeNS(writer, prefix, name, namespaceURI,
2116 * xmlTextWriterWriteAttributeNS:
2117 * @writer: the xmlTextWriterPtr
2118 * @prefix: namespace prefix
2119 * @name: attribute local name
2120 * @namespaceURI: namespace URI
2121 * @content: attribute content
2123 * Write an xml attribute.
2125 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2128 xmlTextWriterWriteAttributeNS(xmlTextWriterPtr writer,
2129 const xmlChar * prefix, const xmlChar * name,
2130 const xmlChar * namespaceURI,
2131 const xmlChar * content)
2136 if ((writer == NULL) || (name == NULL) || (*name == '\0'))
2140 count = xmlTextWriterStartAttributeNS(writer, prefix, name, namespaceURI);
2144 count = xmlTextWriterWriteString(writer, content);
2148 count = xmlTextWriterEndAttribute(writer);
2157 * xmlTextWriterWriteFormatElement:
2158 * @writer: the xmlTextWriterPtr
2159 * @name: element name
2160 * @format: format string (see printf)
2161 * @...: extra parameters for the format
2163 * Write a formatted xml element.
2165 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2168 xmlTextWriterWriteFormatElement(xmlTextWriterPtr writer,
2169 const xmlChar * name, const char *format,
2175 va_start(ap, format);
2177 rc = xmlTextWriterWriteVFormatElement(writer, name, format, ap);
2184 * xmlTextWriterWriteVFormatElement:
2185 * @writer: the xmlTextWriterPtr
2186 * @name: element name
2187 * @format: format string (see printf)
2188 * @argptr: pointer to the first member of the variable argument list.
2190 * Write a formatted xml element.
2192 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2195 xmlTextWriterWriteVFormatElement(xmlTextWriterPtr writer,
2196 const xmlChar * name, const char *format,
2205 buf = xmlTextWriterVSprintf(format, argptr);
2209 rc = xmlTextWriterWriteElement(writer, name, buf);
2216 * xmlTextWriterWriteElement:
2217 * @writer: the xmlTextWriterPtr
2218 * @name: element name
2219 * @content: element content
2221 * Write an xml element.
2223 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2226 xmlTextWriterWriteElement(xmlTextWriterPtr writer, const xmlChar * name,
2227 const xmlChar * content)
2233 count = xmlTextWriterStartElement(writer, name);
2237 count = xmlTextWriterWriteString(writer, content);
2241 count = xmlTextWriterEndElement(writer);
2250 * xmlTextWriterWriteFormatElementNS:
2251 * @writer: the xmlTextWriterPtr
2252 * @prefix: namespace prefix
2253 * @name: element local name
2254 * @namespaceURI: namespace URI
2255 * @format: format string (see printf)
2256 * @...: extra parameters for the format
2258 * Write a formatted xml element with namespace support.
2260 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2263 xmlTextWriterWriteFormatElementNS(xmlTextWriterPtr writer,
2264 const xmlChar * prefix,
2265 const xmlChar * name,
2266 const xmlChar * namespaceURI,
2267 const char *format, ...)
2272 va_start(ap, format);
2274 rc = xmlTextWriterWriteVFormatElementNS(writer, prefix, name,
2275 namespaceURI, format, ap);
2282 * xmlTextWriterWriteVFormatElementNS:
2283 * @writer: the xmlTextWriterPtr
2284 * @prefix: namespace prefix
2285 * @name: element local name
2286 * @namespaceURI: namespace URI
2287 * @format: format string (see printf)
2288 * @argptr: pointer to the first member of the variable argument list.
2290 * Write a formatted xml element with namespace support.
2292 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2295 xmlTextWriterWriteVFormatElementNS(xmlTextWriterPtr writer,
2296 const xmlChar * prefix,
2297 const xmlChar * name,
2298 const xmlChar * namespaceURI,
2299 const char *format, va_list argptr)
2307 buf = xmlTextWriterVSprintf(format, argptr);
2311 rc = xmlTextWriterWriteElementNS(writer, prefix, name, namespaceURI,
2319 * xmlTextWriterWriteElementNS:
2320 * @writer: the xmlTextWriterPtr
2321 * @prefix: namespace prefix
2322 * @name: element local name
2323 * @namespaceURI: namespace URI
2324 * @content: element content
2326 * Write an xml element with namespace support.
2328 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2331 xmlTextWriterWriteElementNS(xmlTextWriterPtr writer,
2332 const xmlChar * prefix, const xmlChar * name,
2333 const xmlChar * namespaceURI,
2334 const xmlChar * content)
2339 if ((writer == NULL) || (name == NULL) || (*name == '\0'))
2344 xmlTextWriterStartElementNS(writer, prefix, name, namespaceURI);
2348 count = xmlTextWriterWriteString(writer, content);
2352 count = xmlTextWriterEndElement(writer);
2361 * xmlTextWriterStartPI:
2362 * @writer: the xmlTextWriterPtr
2363 * @target: PI target
2367 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2370 xmlTextWriterStartPI(xmlTextWriterPtr writer, const xmlChar * target)
2375 xmlTextWriterStackEntry *p;
2377 if ((writer == NULL) || (target == NULL) || (*target == '\0'))
2380 if (xmlStrcasecmp(target, (const xmlChar *) "xml") == 0) {
2381 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
2382 "xmlTextWriterStartPI : target name [Xx][Mm][Ll] is reserved for xml standardization!\n");
2387 lk = xmlListFront(writer->nodes);
2389 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
2392 case XML_TEXTWRITER_ATTRIBUTE:
2393 count = xmlTextWriterEndAttribute(writer);
2398 case XML_TEXTWRITER_NAME:
2399 /* Output namespace declarations */
2400 count = xmlTextWriterOutputNSDecl(writer);
2404 count = xmlOutputBufferWriteString(writer->out, ">");
2408 p->state = XML_TEXTWRITER_TEXT;
2410 case XML_TEXTWRITER_NONE:
2411 case XML_TEXTWRITER_TEXT:
2412 case XML_TEXTWRITER_DTD:
2414 case XML_TEXTWRITER_PI:
2415 case XML_TEXTWRITER_PI_TEXT:
2416 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
2417 "xmlTextWriterStartPI : nested PI!\n");
2425 p = (xmlTextWriterStackEntry *)
2426 xmlMalloc(sizeof(xmlTextWriterStackEntry));
2428 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
2429 "xmlTextWriterStartPI : out of memory!\n");
2433 p->name = xmlStrdup(target);
2435 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
2436 "xmlTextWriterStartPI : out of memory!\n");
2440 p->state = XML_TEXTWRITER_PI;
2442 xmlListPushFront(writer->nodes, p);
2444 count = xmlOutputBufferWriteString(writer->out, "<?");
2449 xmlOutputBufferWriteString(writer->out, (const char *) p->name);
2458 * xmlTextWriterEndPI:
2459 * @writer: the xmlTextWriterPtr
2461 * End the current xml PI.
2463 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2466 xmlTextWriterEndPI(xmlTextWriterPtr writer)
2471 xmlTextWriterStackEntry *p;
2476 lk = xmlListFront(writer->nodes);
2480 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
2486 case XML_TEXTWRITER_PI:
2487 case XML_TEXTWRITER_PI_TEXT:
2488 count = xmlOutputBufferWriteString(writer->out, "?>");
2497 if (writer->indent) {
2498 count = xmlOutputBufferWriteString(writer->out, "\n");
2504 xmlListPopFront(writer->nodes);
2509 * xmlTextWriterWriteFormatPI:
2510 * @writer: the xmlTextWriterPtr
2511 * @target: PI target
2512 * @format: format string (see printf)
2513 * @...: extra parameters for the format
2515 * Write a formatted PI.
2517 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2520 xmlTextWriterWriteFormatPI(xmlTextWriterPtr writer, const xmlChar * target,
2521 const char *format, ...)
2526 va_start(ap, format);
2528 rc = xmlTextWriterWriteVFormatPI(writer, target, format, ap);
2535 * xmlTextWriterWriteVFormatPI:
2536 * @writer: the xmlTextWriterPtr
2537 * @target: PI target
2538 * @format: format string (see printf)
2539 * @argptr: pointer to the first member of the variable argument list.
2541 * Write a formatted xml PI.
2543 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2546 xmlTextWriterWriteVFormatPI(xmlTextWriterPtr writer,
2547 const xmlChar * target, const char *format,
2556 buf = xmlTextWriterVSprintf(format, argptr);
2560 rc = xmlTextWriterWritePI(writer, target, buf);
2567 * xmlTextWriterWritePI:
2568 * @writer: the xmlTextWriterPtr
2569 * @target: PI target
2570 * @content: PI content
2574 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2577 xmlTextWriterWritePI(xmlTextWriterPtr writer, const xmlChar * target,
2578 const xmlChar * content)
2584 count = xmlTextWriterStartPI(writer, target);
2589 count = xmlTextWriterWriteString(writer, content);
2594 count = xmlTextWriterEndPI(writer);
2603 * xmlTextWriterStartCDATA:
2604 * @writer: the xmlTextWriterPtr
2606 * Start an xml CDATA section.
2608 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2611 xmlTextWriterStartCDATA(xmlTextWriterPtr writer)
2616 xmlTextWriterStackEntry *p;
2622 lk = xmlListFront(writer->nodes);
2624 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
2627 case XML_TEXTWRITER_NONE:
2628 case XML_TEXTWRITER_TEXT:
2629 case XML_TEXTWRITER_PI:
2630 case XML_TEXTWRITER_PI_TEXT:
2632 case XML_TEXTWRITER_ATTRIBUTE:
2633 count = xmlTextWriterEndAttribute(writer);
2638 case XML_TEXTWRITER_NAME:
2639 /* Output namespace declarations */
2640 count = xmlTextWriterOutputNSDecl(writer);
2644 count = xmlOutputBufferWriteString(writer->out, ">");
2648 p->state = XML_TEXTWRITER_TEXT;
2650 case XML_TEXTWRITER_CDATA:
2651 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
2652 "xmlTextWriterStartCDATA : CDATA not allowed in this context!\n");
2660 p = (xmlTextWriterStackEntry *)
2661 xmlMalloc(sizeof(xmlTextWriterStackEntry));
2663 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
2664 "xmlTextWriterStartCDATA : out of memory!\n");
2669 p->state = XML_TEXTWRITER_CDATA;
2671 xmlListPushFront(writer->nodes, p);
2673 count = xmlOutputBufferWriteString(writer->out, "<![CDATA[");
2682 * xmlTextWriterEndCDATA:
2683 * @writer: the xmlTextWriterPtr
2685 * End an xml CDATA section.
2687 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2690 xmlTextWriterEndCDATA(xmlTextWriterPtr writer)
2695 xmlTextWriterStackEntry *p;
2700 lk = xmlListFront(writer->nodes);
2704 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
2710 case XML_TEXTWRITER_CDATA:
2711 count = xmlOutputBufferWriteString(writer->out, "]]>");
2720 xmlListPopFront(writer->nodes);
2725 * xmlTextWriterWriteFormatCDATA:
2726 * @writer: the xmlTextWriterPtr
2727 * @format: format string (see printf)
2728 * @...: extra parameters for the format
2730 * Write a formatted xml CDATA.
2732 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2735 xmlTextWriterWriteFormatCDATA(xmlTextWriterPtr writer, const char *format,
2741 va_start(ap, format);
2743 rc = xmlTextWriterWriteVFormatCDATA(writer, format, ap);
2750 * xmlTextWriterWriteVFormatCDATA:
2751 * @writer: the xmlTextWriterPtr
2752 * @format: format string (see printf)
2753 * @argptr: pointer to the first member of the variable argument list.
2755 * Write a formatted xml CDATA.
2757 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2760 xmlTextWriterWriteVFormatCDATA(xmlTextWriterPtr writer, const char *format,
2769 buf = xmlTextWriterVSprintf(format, argptr);
2773 rc = xmlTextWriterWriteCDATA(writer, buf);
2780 * xmlTextWriterWriteCDATA:
2781 * @writer: the xmlTextWriterPtr
2782 * @content: CDATA content
2784 * Write an xml CDATA.
2786 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2789 xmlTextWriterWriteCDATA(xmlTextWriterPtr writer, const xmlChar * content)
2795 count = xmlTextWriterStartCDATA(writer);
2800 count = xmlTextWriterWriteString(writer, content);
2805 count = xmlTextWriterEndCDATA(writer);
2814 * xmlTextWriterStartDTD:
2815 * @writer: the xmlTextWriterPtr
2816 * @name: the name of the DTD
2817 * @pubid: the public identifier, which is an alternative to the system identifier
2818 * @sysid: the system identifier, which is the URI of the DTD
2822 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2825 xmlTextWriterStartDTD(xmlTextWriterPtr writer,
2826 const xmlChar * name,
2827 const xmlChar * pubid, const xmlChar * sysid)
2832 xmlTextWriterStackEntry *p;
2834 if (writer == NULL || name == NULL || *name == '\0')
2838 lk = xmlListFront(writer->nodes);
2839 if ((lk != NULL) && (xmlLinkGetData(lk) != NULL)) {
2840 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
2841 "xmlTextWriterStartDTD : DTD allowed only in prolog!\n");
2845 p = (xmlTextWriterStackEntry *)
2846 xmlMalloc(sizeof(xmlTextWriterStackEntry));
2848 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
2849 "xmlTextWriterStartDTD : out of memory!\n");
2853 p->name = xmlStrdup(name);
2855 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
2856 "xmlTextWriterStartDTD : out of memory!\n");
2860 p->state = XML_TEXTWRITER_DTD;
2862 xmlListPushFront(writer->nodes, p);
2864 count = xmlOutputBufferWriteString(writer->out, "<!DOCTYPE ");
2868 count = xmlOutputBufferWriteString(writer->out, (const char *) name);
2875 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
2876 "xmlTextWriterStartDTD : system identifier needed!\n");
2881 count = xmlOutputBufferWrite(writer->out, 1, "\n");
2883 count = xmlOutputBufferWrite(writer->out, 1, " ");
2888 count = xmlOutputBufferWriteString(writer->out, "PUBLIC ");
2893 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
2899 xmlOutputBufferWriteString(writer->out, (const char *) pubid);
2904 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
2913 count = xmlOutputBufferWrite(writer->out, 1, "\n");
2915 count = xmlOutputBufferWrite(writer->out, 1, " ");
2919 count = xmlOutputBufferWriteString(writer->out, "SYSTEM ");
2925 count = xmlOutputBufferWriteString(writer->out, "\n ");
2927 count = xmlOutputBufferWrite(writer->out, 1, " ");
2933 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
2939 xmlOutputBufferWriteString(writer->out, (const char *) sysid);
2944 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
2954 * xmlTextWriterEndDTD:
2955 * @writer: the xmlTextWriterPtr
2959 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2962 xmlTextWriterEndDTD(xmlTextWriterPtr writer)
2968 xmlTextWriterStackEntry *p;
2976 lk = xmlListFront(writer->nodes);
2979 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
2983 case XML_TEXTWRITER_DTD_TEXT:
2984 count = xmlOutputBufferWriteString(writer->out, "]");
2989 case XML_TEXTWRITER_DTD:
2990 count = xmlOutputBufferWriteString(writer->out, ">");
2992 if (writer->indent) {
2996 count = xmlOutputBufferWriteString(writer->out, "\n");
2999 xmlListPopFront(writer->nodes);
3001 case XML_TEXTWRITER_DTD_ELEM:
3002 case XML_TEXTWRITER_DTD_ELEM_TEXT:
3003 count = xmlTextWriterEndDTDElement(writer);
3005 case XML_TEXTWRITER_DTD_ATTL:
3006 case XML_TEXTWRITER_DTD_ATTL_TEXT:
3007 count = xmlTextWriterEndDTDAttlist(writer);
3009 case XML_TEXTWRITER_DTD_ENTY:
3010 case XML_TEXTWRITER_DTD_PENT:
3011 case XML_TEXTWRITER_DTD_ENTY_TEXT:
3012 count = xmlTextWriterEndDTDEntity(writer);
3014 case XML_TEXTWRITER_COMMENT:
3015 count = xmlTextWriterEndComment(writer);
3031 * xmlTextWriterWriteFormatDTD:
3032 * @writer: the xmlTextWriterPtr
3033 * @name: the name of the DTD
3034 * @pubid: the public identifier, which is an alternative to the system identifier
3035 * @sysid: the system identifier, which is the URI of the DTD
3036 * @format: format string (see printf)
3037 * @...: extra parameters for the format
3039 * Write a DTD with a formatted markup declarations part.
3041 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3044 xmlTextWriterWriteFormatDTD(xmlTextWriterPtr writer,
3045 const xmlChar * name,
3046 const xmlChar * pubid,
3047 const xmlChar * sysid, const char *format, ...)
3052 va_start(ap, format);
3054 rc = xmlTextWriterWriteVFormatDTD(writer, name, pubid, sysid, format,
3062 * xmlTextWriterWriteVFormatDTD:
3063 * @writer: the xmlTextWriterPtr
3064 * @name: the name of the DTD
3065 * @pubid: the public identifier, which is an alternative to the system identifier
3066 * @sysid: the system identifier, which is the URI of the DTD
3067 * @format: format string (see printf)
3068 * @argptr: pointer to the first member of the variable argument list.
3070 * Write a DTD with a formatted markup declarations part.
3072 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3075 xmlTextWriterWriteVFormatDTD(xmlTextWriterPtr writer,
3076 const xmlChar * name,
3077 const xmlChar * pubid,
3078 const xmlChar * sysid,
3079 const char *format, va_list argptr)
3087 buf = xmlTextWriterVSprintf(format, argptr);
3091 rc = xmlTextWriterWriteDTD(writer, name, pubid, sysid, buf);
3098 * xmlTextWriterWriteDTD:
3099 * @writer: the xmlTextWriterPtr
3100 * @name: the name of the DTD
3101 * @pubid: the public identifier, which is an alternative to the system identifier
3102 * @sysid: the system identifier, which is the URI of the DTD
3103 * @subset: string content of the DTD
3107 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3110 xmlTextWriterWriteDTD(xmlTextWriterPtr writer,
3111 const xmlChar * name,
3112 const xmlChar * pubid,
3113 const xmlChar * sysid, const xmlChar * subset)
3119 count = xmlTextWriterStartDTD(writer, name, pubid, sysid);
3124 count = xmlTextWriterWriteString(writer, subset);
3129 count = xmlTextWriterEndDTD(writer);
3138 * xmlTextWriterStartDTDElement:
3139 * @writer: the xmlTextWriterPtr
3140 * @name: the name of the DTD element
3142 * Start an xml DTD element.
3144 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3147 xmlTextWriterStartDTDElement(xmlTextWriterPtr writer, const xmlChar * name)
3152 xmlTextWriterStackEntry *p;
3154 if (writer == NULL || name == NULL || *name == '\0')
3158 lk = xmlListFront(writer->nodes);
3163 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3166 case XML_TEXTWRITER_DTD:
3167 count = xmlOutputBufferWriteString(writer->out, " [");
3171 if (writer->indent) {
3172 count = xmlOutputBufferWriteString(writer->out, "\n");
3177 p->state = XML_TEXTWRITER_DTD_TEXT;
3179 case XML_TEXTWRITER_DTD_TEXT:
3180 case XML_TEXTWRITER_NONE:
3187 p = (xmlTextWriterStackEntry *)
3188 xmlMalloc(sizeof(xmlTextWriterStackEntry));
3190 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
3191 "xmlTextWriterStartDTDElement : out of memory!\n");
3195 p->name = xmlStrdup(name);
3197 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
3198 "xmlTextWriterStartDTDElement : out of memory!\n");
3202 p->state = XML_TEXTWRITER_DTD_ELEM;
3204 xmlListPushFront(writer->nodes, p);
3206 if (writer->indent) {
3207 count = xmlTextWriterWriteIndent(writer);
3213 count = xmlOutputBufferWriteString(writer->out, "<!ELEMENT ");
3217 count = xmlOutputBufferWriteString(writer->out, (const char *) name);
3226 * xmlTextWriterEndDTDElement:
3227 * @writer: the xmlTextWriterPtr
3229 * End an xml DTD element.
3231 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3234 xmlTextWriterEndDTDElement(xmlTextWriterPtr writer)
3239 xmlTextWriterStackEntry *p;
3245 lk = xmlListFront(writer->nodes);
3249 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3254 case XML_TEXTWRITER_DTD_ELEM:
3255 case XML_TEXTWRITER_DTD_ELEM_TEXT:
3256 count = xmlOutputBufferWriteString(writer->out, ">");
3265 if (writer->indent) {
3266 count = xmlOutputBufferWriteString(writer->out, "\n");
3272 xmlListPopFront(writer->nodes);
3277 * xmlTextWriterWriteFormatDTDElement:
3278 * @writer: the xmlTextWriterPtr
3279 * @name: the name of the DTD element
3280 * @format: format string (see printf)
3281 * @...: extra parameters for the format
3283 * Write a formatted DTD element.
3285 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3288 xmlTextWriterWriteFormatDTDElement(xmlTextWriterPtr writer,
3289 const xmlChar * name,
3290 const char *format, ...)
3295 va_start(ap, format);
3297 rc = xmlTextWriterWriteVFormatDTDElement(writer, name, format, ap);
3304 * xmlTextWriterWriteVFormatDTDElement:
3305 * @writer: the xmlTextWriterPtr
3306 * @name: the name of the DTD element
3307 * @format: format string (see printf)
3308 * @argptr: pointer to the first member of the variable argument list.
3310 * Write a formatted DTD element.
3312 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3315 xmlTextWriterWriteVFormatDTDElement(xmlTextWriterPtr writer,
3316 const xmlChar * name,
3317 const char *format, va_list argptr)
3325 buf = xmlTextWriterVSprintf(format, argptr);
3329 rc = xmlTextWriterWriteDTDElement(writer, name, buf);
3336 * xmlTextWriterWriteDTDElement:
3337 * @writer: the xmlTextWriterPtr
3338 * @name: the name of the DTD element
3339 * @content: content of the element
3341 * Write a DTD element.
3343 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3346 xmlTextWriterWriteDTDElement(xmlTextWriterPtr writer,
3347 const xmlChar * name, const xmlChar * content)
3352 if (content == NULL)
3356 count = xmlTextWriterStartDTDElement(writer, name);
3361 count = xmlTextWriterWriteString(writer, content);
3366 count = xmlTextWriterEndDTDElement(writer);
3375 * xmlTextWriterStartDTDAttlist:
3376 * @writer: the xmlTextWriterPtr
3377 * @name: the name of the DTD ATTLIST
3379 * Start an xml DTD ATTLIST.
3381 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3384 xmlTextWriterStartDTDAttlist(xmlTextWriterPtr writer, const xmlChar * name)
3389 xmlTextWriterStackEntry *p;
3391 if (writer == NULL || name == NULL || *name == '\0')
3395 lk = xmlListFront(writer->nodes);
3400 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3403 case XML_TEXTWRITER_DTD:
3404 count = xmlOutputBufferWriteString(writer->out, " [");
3408 if (writer->indent) {
3409 count = xmlOutputBufferWriteString(writer->out, "\n");
3414 p->state = XML_TEXTWRITER_DTD_TEXT;
3416 case XML_TEXTWRITER_DTD_TEXT:
3417 case XML_TEXTWRITER_NONE:
3424 p = (xmlTextWriterStackEntry *)
3425 xmlMalloc(sizeof(xmlTextWriterStackEntry));
3427 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
3428 "xmlTextWriterStartDTDAttlist : out of memory!\n");
3432 p->name = xmlStrdup(name);
3434 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
3435 "xmlTextWriterStartDTDAttlist : out of memory!\n");
3439 p->state = XML_TEXTWRITER_DTD_ATTL;
3441 xmlListPushFront(writer->nodes, p);
3443 if (writer->indent) {
3444 count = xmlTextWriterWriteIndent(writer);
3450 count = xmlOutputBufferWriteString(writer->out, "<!ATTLIST ");
3454 count = xmlOutputBufferWriteString(writer->out, (const char *) name);
3463 * xmlTextWriterEndDTDAttlist:
3464 * @writer: the xmlTextWriterPtr
3466 * End an xml DTD attribute list.
3468 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3471 xmlTextWriterEndDTDAttlist(xmlTextWriterPtr writer)
3476 xmlTextWriterStackEntry *p;
3482 lk = xmlListFront(writer->nodes);
3486 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3491 case XML_TEXTWRITER_DTD_ATTL:
3492 case XML_TEXTWRITER_DTD_ATTL_TEXT:
3493 count = xmlOutputBufferWriteString(writer->out, ">");
3502 if (writer->indent) {
3503 count = xmlOutputBufferWriteString(writer->out, "\n");
3509 xmlListPopFront(writer->nodes);
3514 * xmlTextWriterWriteFormatDTDAttlist:
3515 * @writer: the xmlTextWriterPtr
3516 * @name: the name of the DTD ATTLIST
3517 * @format: format string (see printf)
3518 * @...: extra parameters for the format
3520 * Write a formatted DTD ATTLIST.
3522 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3525 xmlTextWriterWriteFormatDTDAttlist(xmlTextWriterPtr writer,
3526 const xmlChar * name,
3527 const char *format, ...)
3532 va_start(ap, format);
3534 rc = xmlTextWriterWriteVFormatDTDAttlist(writer, name, format, ap);
3541 * xmlTextWriterWriteVFormatDTDAttlist:
3542 * @writer: the xmlTextWriterPtr
3543 * @name: the name of the DTD ATTLIST
3544 * @format: format string (see printf)
3545 * @argptr: pointer to the first member of the variable argument list.
3547 * Write a formatted DTD ATTLIST.
3549 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3552 xmlTextWriterWriteVFormatDTDAttlist(xmlTextWriterPtr writer,
3553 const xmlChar * name,
3554 const char *format, va_list argptr)
3562 buf = xmlTextWriterVSprintf(format, argptr);
3566 rc = xmlTextWriterWriteDTDAttlist(writer, name, buf);
3573 * xmlTextWriterWriteDTDAttlist:
3574 * @writer: the xmlTextWriterPtr
3575 * @name: the name of the DTD ATTLIST
3576 * @content: content of the ATTLIST
3578 * Write a DTD ATTLIST.
3580 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3583 xmlTextWriterWriteDTDAttlist(xmlTextWriterPtr writer,
3584 const xmlChar * name, const xmlChar * content)
3589 if (content == NULL)
3593 count = xmlTextWriterStartDTDAttlist(writer, name);
3598 count = xmlTextWriterWriteString(writer, content);
3603 count = xmlTextWriterEndDTDAttlist(writer);
3612 * xmlTextWriterStartDTDEntity:
3613 * @writer: the xmlTextWriterPtr
3614 * @pe: TRUE if this is a parameter entity, FALSE if not
3615 * @name: the name of the DTD ATTLIST
3617 * Start an xml DTD ATTLIST.
3619 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3622 xmlTextWriterStartDTDEntity(xmlTextWriterPtr writer,
3623 int pe, const xmlChar * name)
3628 xmlTextWriterStackEntry *p;
3630 if (writer == NULL || name == NULL || *name == '\0')
3634 lk = xmlListFront(writer->nodes);
3637 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3640 case XML_TEXTWRITER_DTD:
3641 count = xmlOutputBufferWriteString(writer->out, " [");
3645 if (writer->indent) {
3647 xmlOutputBufferWriteString(writer->out, "\n");
3652 p->state = XML_TEXTWRITER_DTD_TEXT;
3654 case XML_TEXTWRITER_DTD_TEXT:
3655 case XML_TEXTWRITER_NONE:
3663 p = (xmlTextWriterStackEntry *)
3664 xmlMalloc(sizeof(xmlTextWriterStackEntry));
3666 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
3667 "xmlTextWriterStartDTDElement : out of memory!\n");
3671 p->name = xmlStrdup(name);
3673 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
3674 "xmlTextWriterStartDTDElement : out of memory!\n");
3680 p->state = XML_TEXTWRITER_DTD_PENT;
3682 p->state = XML_TEXTWRITER_DTD_ENTY;
3684 xmlListPushFront(writer->nodes, p);
3686 if (writer->indent) {
3687 count = xmlTextWriterWriteIndent(writer);
3693 count = xmlOutputBufferWriteString(writer->out, "<!ENTITY ");
3699 count = xmlOutputBufferWriteString(writer->out, "% ");
3705 count = xmlOutputBufferWriteString(writer->out, (const char *) name);
3714 * xmlTextWriterEndDTDEntity:
3715 * @writer: the xmlTextWriterPtr
3717 * End an xml DTD entity.
3719 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3722 xmlTextWriterEndDTDEntity(xmlTextWriterPtr writer)
3727 xmlTextWriterStackEntry *p;
3733 lk = xmlListFront(writer->nodes);
3737 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3742 case XML_TEXTWRITER_DTD_ENTY_TEXT:
3743 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
3747 case XML_TEXTWRITER_DTD_ENTY:
3748 case XML_TEXTWRITER_DTD_PENT:
3749 count = xmlOutputBufferWriteString(writer->out, ">");
3758 if (writer->indent) {
3759 count = xmlOutputBufferWriteString(writer->out, "\n");
3765 xmlListPopFront(writer->nodes);
3770 * xmlTextWriterWriteFormatDTDInternalEntity:
3771 * @writer: the xmlTextWriterPtr
3772 * @pe: TRUE if this is a parameter entity, FALSE if not
3773 * @name: the name of the DTD entity
3774 * @format: format string (see printf)
3775 * @...: extra parameters for the format
3777 * Write a formatted DTD internal entity.
3779 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3782 xmlTextWriterWriteFormatDTDInternalEntity(xmlTextWriterPtr writer,
3784 const xmlChar * name,
3785 const char *format, ...)
3790 va_start(ap, format);
3792 rc = xmlTextWriterWriteVFormatDTDInternalEntity(writer, pe, name,
3800 * xmlTextWriterWriteVFormatDTDInternalEntity:
3801 * @writer: the xmlTextWriterPtr
3802 * @pe: TRUE if this is a parameter entity, FALSE if not
3803 * @name: the name of the DTD entity
3804 * @format: format string (see printf)
3805 * @argptr: pointer to the first member of the variable argument list.
3807 * Write a formatted DTD internal entity.
3809 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3812 xmlTextWriterWriteVFormatDTDInternalEntity(xmlTextWriterPtr writer,
3814 const xmlChar * name,
3824 buf = xmlTextWriterVSprintf(format, argptr);
3828 rc = xmlTextWriterWriteDTDInternalEntity(writer, pe, name, buf);
3835 * xmlTextWriterWriteDTDEntity:
3836 * @writer: the xmlTextWriterPtr
3837 * @pe: TRUE if this is a parameter entity, FALSE if not
3838 * @name: the name of the DTD entity
3839 * @pubid: the public identifier, which is an alternative to the system identifier
3840 * @sysid: the system identifier, which is the URI of the DTD
3841 * @ndataid: the xml notation name.
3842 * @content: content of the entity
3844 * Write a DTD entity.
3846 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3849 xmlTextWriterWriteDTDEntity(xmlTextWriterPtr writer,
3851 const xmlChar * name,
3852 const xmlChar * pubid,
3853 const xmlChar * sysid,
3854 const xmlChar * ndataid,
3855 const xmlChar * content)
3857 if ((content == NULL) && (pubid == NULL) && (sysid == NULL))
3859 if ((pe != 0) && (ndataid != NULL))
3862 if ((pubid == NULL) && (sysid == NULL))
3863 return xmlTextWriterWriteDTDInternalEntity(writer, pe, name,
3866 return xmlTextWriterWriteDTDExternalEntity(writer, pe, name, pubid,
3871 * xmlTextWriterWriteDTDInternalEntity:
3872 * @writer: the xmlTextWriterPtr
3873 * @pe: TRUE if this is a parameter entity, FALSE if not
3874 * @name: the name of the DTD entity
3875 * @content: content of the entity
3877 * Write a DTD internal entity.
3879 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3882 xmlTextWriterWriteDTDInternalEntity(xmlTextWriterPtr writer,
3884 const xmlChar * name,
3885 const xmlChar * content)
3890 if ((name == NULL) || (*name == '\0') || (content == NULL))
3894 count = xmlTextWriterStartDTDEntity(writer, pe, name);
3899 count = xmlTextWriterWriteString(writer, content);
3904 count = xmlTextWriterEndDTDEntity(writer);
3913 * xmlTextWriterWriteDTDExternalEntity:
3914 * @writer: the xmlTextWriterPtr
3915 * @pe: TRUE if this is a parameter entity, FALSE if not
3916 * @name: the name of the DTD entity
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 a DTD external entity. The entity must have been started with xmlTextWriterStartDTDEntity
3923 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3926 xmlTextWriterWriteDTDExternalEntity(xmlTextWriterPtr writer,
3928 const xmlChar * name,
3929 const xmlChar * pubid,
3930 const xmlChar * sysid,
3931 const xmlChar * ndataid)
3936 if (((pubid == NULL) && (sysid == NULL)))
3938 if ((pe != 0) && (ndataid != NULL))
3942 count = xmlTextWriterStartDTDEntity(writer, pe, name);
3948 xmlTextWriterWriteDTDExternalEntityContents(writer, pubid, sysid,
3954 count = xmlTextWriterEndDTDEntity(writer);
3963 * xmlTextWriterWriteDTDExternalEntityContents:
3964 * @writer: the xmlTextWriterPtr
3965 * @pubid: the public identifier, which is an alternative to the system identifier
3966 * @sysid: the system identifier, which is the URI of the DTD
3967 * @ndataid: the xml notation name.
3969 * Write the contents of a DTD external entity.
3971 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3974 xmlTextWriterWriteDTDExternalEntityContents(xmlTextWriterPtr writer,
3975 const xmlChar * pubid,
3976 const xmlChar * sysid,
3977 const xmlChar * ndataid)
3982 xmlTextWriterStackEntry *p;
3984 if (writer == NULL) {
3985 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
3986 "xmlTextWriterWriteDTDExternalEntityContents: xmlTextWriterPtr invalid!\n");
3991 lk = xmlListFront(writer->nodes);
3993 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
3994 "xmlTextWriterWriteDTDExternalEntityContents: you must call xmlTextWriterStartDTDEntity before the call to this function!\n");
3998 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
4003 case XML_TEXTWRITER_DTD_ENTY:
4005 case XML_TEXTWRITER_DTD_PENT:
4006 if (ndataid != NULL) {
4007 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
4008 "xmlTextWriterWriteDTDExternalEntityContents: notation not allowed with parameter entities!\n");
4013 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
4014 "xmlTextWriterWriteDTDExternalEntityContents: you must call xmlTextWriterStartDTDEntity before the call to this function!\n");
4020 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
4021 "xmlTextWriterWriteDTDExternalEntityContents: system identifier needed!\n");
4025 count = xmlOutputBufferWriteString(writer->out, " PUBLIC ");
4030 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
4036 xmlOutputBufferWriteString(writer->out, (const char *) pubid);
4041 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
4049 count = xmlOutputBufferWriteString(writer->out, " SYSTEM");
4055 count = xmlOutputBufferWriteString(writer->out, " ");
4060 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
4066 xmlOutputBufferWriteString(writer->out, (const char *) sysid);
4071 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
4077 if (ndataid != NULL) {
4078 count = xmlOutputBufferWriteString(writer->out, " NDATA ");
4084 xmlOutputBufferWriteString(writer->out,
4085 (const char *) ndataid);
4095 * xmlTextWriterWriteDTDNotation:
4096 * @writer: the xmlTextWriterPtr
4097 * @name: the name of the xml notation
4098 * @pubid: the public identifier, which is an alternative to the system identifier
4099 * @sysid: the system identifier, which is the URI of the DTD
4101 * Write a DTD entity.
4103 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
4106 xmlTextWriterWriteDTDNotation(xmlTextWriterPtr writer,
4107 const xmlChar * name,
4108 const xmlChar * pubid, const xmlChar * sysid)
4113 xmlTextWriterStackEntry *p;
4115 if (writer == NULL || name == NULL || *name == '\0')
4119 lk = xmlListFront(writer->nodes);
4124 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
4127 case XML_TEXTWRITER_DTD:
4128 count = xmlOutputBufferWriteString(writer->out, " [");
4132 if (writer->indent) {
4133 count = xmlOutputBufferWriteString(writer->out, "\n");
4138 p->state = XML_TEXTWRITER_DTD_TEXT;
4140 case XML_TEXTWRITER_DTD_TEXT:
4147 if (writer->indent) {
4148 count = xmlTextWriterWriteIndent(writer);
4154 count = xmlOutputBufferWriteString(writer->out, "<!NOTATION ");
4158 count = xmlOutputBufferWriteString(writer->out, (const char *) name);
4164 count = xmlOutputBufferWriteString(writer->out, " PUBLIC ");
4168 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
4173 xmlOutputBufferWriteString(writer->out, (const char *) pubid);
4177 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
4185 count = xmlOutputBufferWriteString(writer->out, " SYSTEM");
4190 count = xmlOutputBufferWriteString(writer->out, " ");
4194 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
4199 xmlOutputBufferWriteString(writer->out, (const char *) sysid);
4203 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
4209 count = xmlOutputBufferWriteString(writer->out, ">");
4218 * xmlTextWriterFlush:
4219 * @writer: the xmlTextWriterPtr
4221 * Flush the output buffer.
4223 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
4226 xmlTextWriterFlush(xmlTextWriterPtr writer)
4233 if (writer->out == NULL)
4236 count = xmlOutputBufferFlush(writer->out);
4246 * xmlFreeTextWriterStackEntry:
4247 * @lk: the xmlLinkPtr
4249 * Free callback for the xmlList.
4252 xmlFreeTextWriterStackEntry(xmlLinkPtr lk)
4254 xmlTextWriterStackEntry *p;
4256 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
4266 * xmlCmpTextWriterStackEntry:
4267 * @data0: the first data
4268 * @data1: the second data
4270 * Compare callback for the xmlList.
4275 xmlCmpTextWriterStackEntry(const void *data0, const void *data1)
4277 xmlTextWriterStackEntry *p0;
4278 xmlTextWriterStackEntry *p1;
4289 p0 = (xmlTextWriterStackEntry *) data0;
4290 p1 = (xmlTextWriterStackEntry *) data1;
4292 return xmlStrcmp(p0->name, p1->name);
4300 * xmlTextWriterOutputNSDecl:
4301 * @writer: the xmlTextWriterPtr
4303 * Output the current namespace declarations.
4306 xmlTextWriterOutputNSDecl(xmlTextWriterPtr writer)
4309 xmlTextWriterNsStackEntry *np;
4314 while (!xmlListEmpty(writer->nsstack)) {
4315 xmlChar *namespaceURI = NULL;
4316 xmlChar *prefix = NULL;
4318 lk = xmlListFront(writer->nsstack);
4319 np = (xmlTextWriterNsStackEntry *) xmlLinkGetData(lk);
4322 namespaceURI = xmlStrdup(np->uri);
4323 prefix = xmlStrdup(np->prefix);
4326 xmlListPopFront(writer->nsstack);
4329 count = xmlTextWriterWriteAttribute(writer, prefix, namespaceURI);
4330 xmlFree(namespaceURI);
4334 xmlListDelete(writer->nsstack);
4335 writer->nsstack = NULL;
4345 * xmlFreeTextWriterNsStackEntry:
4346 * @lk: the xmlLinkPtr
4348 * Free callback for the xmlList.
4351 xmlFreeTextWriterNsStackEntry(xmlLinkPtr lk)
4353 xmlTextWriterNsStackEntry *p;
4355 p = (xmlTextWriterNsStackEntry *) xmlLinkGetData(lk);
4368 * xmlCmpTextWriterNsStackEntry:
4369 * @data0: the first data
4370 * @data1: the second data
4372 * Compare callback for the xmlList.
4377 xmlCmpTextWriterNsStackEntry(const void *data0, const void *data1)
4379 xmlTextWriterNsStackEntry *p0;
4380 xmlTextWriterNsStackEntry *p1;
4392 p0 = (xmlTextWriterNsStackEntry *) data0;
4393 p1 = (xmlTextWriterNsStackEntry *) data1;
4395 rc = xmlStrcmp(p0->prefix, p1->prefix);
4397 if ((rc != 0) || (p0->elem != p1->elem))
4404 * xmlTextWriterWriteDocCallback:
4405 * @context: the xmlBufferPtr
4406 * @str: the data to write
4407 * @len: the length of the data
4409 * Write callback for the xmlOutputBuffer with target xmlBuffer
4414 xmlTextWriterWriteDocCallback(void *context, const xmlChar * str, int len)
4416 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) context;
4419 if ((rc = xmlParseChunk(ctxt, (const char *) str, len, 0)) != 0) {
4420 xmlWriterErrMsgInt(NULL, XML_ERR_INTERNAL_ERROR,
4421 "xmlTextWriterWriteDocCallback : XML error %d !\n",
4430 * xmlTextWriterCloseDocCallback:
4431 * @context: the xmlBufferPtr
4433 * Close callback for the xmlOutputBuffer with target xmlBuffer
4438 xmlTextWriterCloseDocCallback(void *context)
4440 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) context;
4443 if ((rc = xmlParseChunk(ctxt, NULL, 0, 1)) != 0) {
4444 xmlWriterErrMsgInt(NULL, XML_ERR_INTERNAL_ERROR,
4445 "xmlTextWriterWriteDocCallback : XML error %d !\n",
4454 * xmlTextWriterVSprintf:
4455 * @format: see printf
4456 * @argptr: pointer to the first member of the variable argument list.
4458 * Utility function for formatted output
4460 * Returns a new xmlChar buffer with the data or NULL on error. This buffer must be freed.
4463 xmlTextWriterVSprintf(const char *format, va_list argptr)
4471 buf = (xmlChar *) xmlMalloc(size);
4473 xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
4474 "xmlTextWriterVSprintf : out of memory!\n");
4478 VA_COPY(locarg, argptr);
4479 while (((count = vsnprintf((char *) buf, size, format, locarg)) < 0)
4480 || (count == size - 1) || (count == size) || (count > size)) {
4484 buf = (xmlChar *) xmlMalloc(size);
4486 xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
4487 "xmlTextWriterVSprintf : out of memory!\n");
4490 VA_COPY(locarg, argptr);
4498 * xmlTextWriterStartDocumentCallback:
4499 * @ctx: the user data (XML parser context)
4501 * called at the start of document processing.
4504 xmlTextWriterStartDocumentCallback(void *ctx)
4506 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
4510 #ifdef LIBXML_HTML_ENABLED
4511 if (ctxt->myDoc == NULL)
4512 ctxt->myDoc = htmlNewDocNoDtD(NULL, NULL);
4513 if (ctxt->myDoc == NULL) {
4514 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4515 ctxt->sax->error(ctxt->userData,
4516 "SAX.startDocument(): out of memory\n");
4517 ctxt->errNo = XML_ERR_NO_MEMORY;
4518 ctxt->instate = XML_PARSER_EOF;
4519 ctxt->disableSAX = 1;
4523 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
4524 "libxml2 built without HTML support\n");
4525 ctxt->errNo = XML_ERR_INTERNAL_ERROR;
4526 ctxt->instate = XML_PARSER_EOF;
4527 ctxt->disableSAX = 1;
4533 doc = ctxt->myDoc = xmlNewDoc(ctxt->version);
4535 if (doc->children == NULL) {
4536 if (ctxt->encoding != NULL)
4537 doc->encoding = xmlStrdup(ctxt->encoding);
4539 doc->encoding = NULL;
4540 doc->standalone = ctxt->standalone;
4543 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4544 ctxt->sax->error(ctxt->userData,
4545 "SAX.startDocument(): out of memory\n");
4546 ctxt->errNo = XML_ERR_NO_MEMORY;
4547 ctxt->instate = XML_PARSER_EOF;
4548 ctxt->disableSAX = 1;
4552 if ((ctxt->myDoc != NULL) && (ctxt->myDoc->URL == NULL) &&
4553 (ctxt->input != NULL) && (ctxt->input->filename != NULL)) {
4555 xmlCanonicPath((const xmlChar *) ctxt->input->filename);
4556 if (ctxt->myDoc->URL == NULL)
4558 xmlStrdup((const xmlChar *) ctxt->input->filename);
4563 * xmlTextWriterSetIndent:
4564 * @writer: the xmlTextWriterPtr
4565 * @indent: do indentation?
4567 * Set indentation output. indent = 0 do not indentation. indent > 0 do indentation.
4569 * Returns -1 on error or 0 otherwise.
4572 xmlTextWriterSetIndent(xmlTextWriterPtr writer, int indent)
4574 if ((writer == NULL) || (indent < 0))
4577 writer->indent = indent;
4578 writer->doindent = 1;
4584 * xmlTextWriterSetIndentString:
4585 * @writer: the xmlTextWriterPtr
4586 * @str: the xmlChar string
4588 * Set string indentation.
4590 * Returns -1 on error or 0 otherwise.
4593 xmlTextWriterSetIndentString(xmlTextWriterPtr writer, const xmlChar * str)
4595 if ((writer == NULL) || (!str))
4598 if (writer->ichar != NULL)
4599 xmlFree(writer->ichar);
4600 writer->ichar = xmlStrdup(str);
4609 * xmlTextWriterWriteIndent:
4610 * @writer: the xmlTextWriterPtr
4612 * Write indent string.
4614 * Returns -1 on error or the number of strings written.
4617 xmlTextWriterWriteIndent(xmlTextWriterPtr writer)
4623 lksize = xmlListSize(writer->nodes);
4625 return (-1); /* list is empty */
4626 for (i = 0; i < (lksize - 1); i++) {
4627 ret = xmlOutputBufferWriteString(writer->out,
4628 (const char *) writer->ichar);
4633 return (lksize - 1);
4637 * xmlTextWriterHandleStateDependencies:
4638 * @writer: the xmlTextWriterPtr
4639 * @p: the xmlTextWriterStackEntry
4641 * Write state dependent strings.
4643 * Returns -1 on error or the number of characters written.
4646 xmlTextWriterHandleStateDependencies(xmlTextWriterPtr writer,
4647 xmlTextWriterStackEntry * p)
4660 extra[0] = extra[1] = extra[2] = '\0';
4664 case XML_TEXTWRITER_NAME:
4665 /* Output namespace declarations */
4666 count = xmlTextWriterOutputNSDecl(writer);
4671 p->state = XML_TEXTWRITER_TEXT;
4673 case XML_TEXTWRITER_PI:
4675 p->state = XML_TEXTWRITER_PI_TEXT;
4677 case XML_TEXTWRITER_DTD:
4680 p->state = XML_TEXTWRITER_DTD_TEXT;
4682 case XML_TEXTWRITER_DTD_ELEM:
4684 p->state = XML_TEXTWRITER_DTD_ELEM_TEXT;
4686 case XML_TEXTWRITER_DTD_ATTL:
4688 p->state = XML_TEXTWRITER_DTD_ATTL_TEXT;
4690 case XML_TEXTWRITER_DTD_ENTY:
4691 case XML_TEXTWRITER_DTD_PENT:
4693 extra[1] = writer->qchar;
4694 p->state = XML_TEXTWRITER_DTD_ENTY_TEXT;
4701 if (*extra != '\0') {
4702 count = xmlOutputBufferWriteString(writer->out, extra);
4711 #define bottom_xmlwriter
4712 #include "elfgcchack.h"