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>
29 #define B64CRLF "\r\n"
32 * The following VA_COPY was coded following an example in
33 * the Samba project. It may not be sufficient for some
34 * esoteric implementations of va_list but (hopefully) will
35 * be sufficient for libxml2.
39 #define VA_COPY(dest, src) va_copy(dest, src)
42 #define VA_COPY(dest,src) __va_copy(dest, src)
44 #ifndef VA_LIST_IS_ARRAY
45 #define VA_COPY(dest,src) (dest) = (src)
48 #define VA_COPY(dest,src) memcpy((char *)(dest),(char *)(src),sizeof(va_list))
55 * Types are kept private
58 XML_TEXTWRITER_NONE = 0,
60 XML_TEXTWRITER_ATTRIBUTE,
63 XML_TEXTWRITER_PI_TEXT,
66 XML_TEXTWRITER_DTD_TEXT,
67 XML_TEXTWRITER_DTD_ELEM,
68 XML_TEXTWRITER_DTD_ELEM_TEXT,
69 XML_TEXTWRITER_DTD_ATTL,
70 XML_TEXTWRITER_DTD_ATTL_TEXT,
71 XML_TEXTWRITER_DTD_ENTY, /* entity */
72 XML_TEXTWRITER_DTD_ENTY_TEXT,
73 XML_TEXTWRITER_DTD_PENT, /* parameter entity */
74 XML_TEXTWRITER_COMMENT
77 typedef struct _xmlTextWriterStackEntry xmlTextWriterStackEntry;
79 struct _xmlTextWriterStackEntry {
81 xmlTextWriterState state;
84 typedef struct _xmlTextWriterNsStackEntry xmlTextWriterNsStackEntry;
85 struct _xmlTextWriterNsStackEntry {
91 struct _xmlTextWriter {
92 xmlOutputBufferPtr out; /* output buffer */
93 xmlListPtr nodes; /* element name stack */
94 xmlListPtr nsstack; /* name spaces stack */
96 int indent; /* enable indent */
97 int doindent; /* internal indent flag */
98 xmlChar *ichar; /* indent character */
99 char qchar; /* character used for quoting attribute values */
100 xmlParserCtxtPtr ctxt;
105 static void xmlFreeTextWriterStackEntry(xmlLinkPtr lk);
106 static int xmlCmpTextWriterStackEntry(const void *data0,
108 static int xmlTextWriterOutputNSDecl(xmlTextWriterPtr writer);
109 static void xmlFreeTextWriterNsStackEntry(xmlLinkPtr lk);
110 static int xmlCmpTextWriterNsStackEntry(const void *data0,
112 static int xmlTextWriterWriteDocCallback(void *context,
113 const xmlChar * str, int len);
114 static int xmlTextWriterCloseDocCallback(void *context);
116 static xmlChar *xmlTextWriterVSprintf(const char *format, va_list argptr);
117 static int xmlOutputBufferWriteBase64(xmlOutputBufferPtr out, int len,
118 const unsigned char *data);
119 static void xmlTextWriterStartDocumentCallback(void *ctx);
120 static int xmlTextWriterWriteIndent(xmlTextWriterPtr writer);
122 xmlTextWriterHandleStateDependencies(xmlTextWriterPtr writer,
123 xmlTextWriterStackEntry * p);
127 * @ctxt: a writer context
128 * @error: the error number
129 * @msg: the error message
131 * Handle a writer error
134 xmlWriterErrMsg(xmlTextWriterPtr ctxt, xmlParserErrors error,
138 __xmlRaiseError(NULL, NULL, NULL, ctxt->ctxt,
139 NULL, XML_FROM_WRITER, error, XML_ERR_FATAL,
140 NULL, 0, NULL, NULL, NULL, 0, 0, "%s", msg);
142 __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_WRITER, error,
143 XML_ERR_FATAL, NULL, 0, NULL, NULL, NULL, 0, 0, "%s", msg);
148 * xmlWriterErrMsgInt:
149 * @ctxt: a writer context
150 * @error: the error number
151 * @msg: the error message
154 * Handle a writer error
157 xmlWriterErrMsgInt(xmlTextWriterPtr ctxt, xmlParserErrors error,
158 const char *msg, int val)
161 __xmlRaiseError(NULL, NULL, NULL, ctxt->ctxt,
162 NULL, XML_FROM_WRITER, error, XML_ERR_FATAL,
163 NULL, 0, NULL, NULL, NULL, val, 0, msg, val);
165 __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_WRITER, error,
166 XML_ERR_FATAL, NULL, 0, NULL, NULL, NULL, val, 0, msg, val);
172 * @out: an xmlOutputBufferPtr
174 * Create a new xmlNewTextWriter structure using an xmlOutputBufferPtr
175 * NOTE: the @out parameter will be deallocated when the writer is closed
176 * (if the call succeed.)
178 * Returns the new xmlTextWriterPtr or NULL in case of error
181 xmlNewTextWriter(xmlOutputBufferPtr out)
183 xmlTextWriterPtr ret;
185 ret = (xmlTextWriterPtr) xmlMalloc(sizeof(xmlTextWriter));
187 xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
188 "xmlNewTextWriter : out of memory!\n");
191 memset(ret, 0, (size_t) sizeof(xmlTextWriter));
193 ret->nodes = xmlListCreate((xmlListDeallocator)
194 xmlFreeTextWriterStackEntry,
196 xmlCmpTextWriterStackEntry);
197 if (ret->nodes == NULL) {
198 xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
199 "xmlNewTextWriter : out of memory!\n");
204 ret->nsstack = xmlListCreate((xmlListDeallocator)
205 xmlFreeTextWriterNsStackEntry,
207 xmlCmpTextWriterNsStackEntry);
208 if (ret->nsstack == NULL) {
209 xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
210 "xmlNewTextWriter : out of memory!\n");
211 xmlListDelete(ret->nodes);
217 ret->ichar = xmlStrdup(BAD_CAST " ");
221 xmlListDelete(ret->nodes);
222 xmlListDelete(ret->nsstack);
224 xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
225 "xmlNewTextWriter : out of memory!\n");
229 ret->doc = xmlNewDoc(NULL);
231 ret->no_doc_free = 0;
237 * xmlNewTextWriterFilename:
238 * @uri: the URI of the resource for the output
239 * @compression: compress the output?
241 * Create a new xmlNewTextWriter structure with @uri as output
243 * Returns the new xmlTextWriterPtr or NULL in case of error
246 xmlNewTextWriterFilename(const char *uri, int compression)
248 xmlTextWriterPtr ret;
249 xmlOutputBufferPtr out;
251 out = xmlOutputBufferCreateFilename(uri, NULL, compression);
253 xmlWriterErrMsg(NULL, XML_IO_EIO,
254 "xmlNewTextWriterFilename : cannot open uri\n");
258 ret = xmlNewTextWriter(out);
260 xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
261 "xmlNewTextWriterFilename : out of memory!\n");
262 xmlOutputBufferClose(out);
272 * xmlNewTextWriterMemory:
274 * @compression: compress the output?
276 * Create a new xmlNewTextWriter structure with @buf as output
277 * TODO: handle compression
279 * Returns the new xmlTextWriterPtr or NULL in case of error
282 xmlNewTextWriterMemory(xmlBufferPtr buf, int compression ATTRIBUTE_UNUSED)
284 xmlTextWriterPtr ret;
285 xmlOutputBufferPtr out;
287 /*::todo handle compression */
288 out = xmlOutputBufferCreateBuffer(buf, NULL);
291 xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
292 "xmlNewTextWriterMemory : out of memory!\n");
296 ret = xmlNewTextWriter(out);
298 xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
299 "xmlNewTextWriterMemory : out of memory!\n");
300 xmlOutputBufferClose(out);
308 * xmlNewTextWriterPushParser:
309 * @ctxt: xmlParserCtxtPtr to hold the new XML document tree
310 * @compression: compress the output?
312 * Create a new xmlNewTextWriter structure with @ctxt as output
313 * NOTE: the @ctxt context will be freed with the resulting writer
314 * (if the call succeeds).
315 * TODO: handle compression
317 * Returns the new xmlTextWriterPtr or NULL in case of error
320 xmlNewTextWriterPushParser(xmlParserCtxtPtr ctxt,
321 int compression ATTRIBUTE_UNUSED)
323 xmlTextWriterPtr ret;
324 xmlOutputBufferPtr out;
327 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
328 "xmlNewTextWriterPushParser : invalid context!\n");
332 out = xmlOutputBufferCreateIO((xmlOutputWriteCallback)
333 xmlTextWriterWriteDocCallback,
334 (xmlOutputCloseCallback)
335 xmlTextWriterCloseDocCallback,
336 (void *) ctxt, NULL);
338 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
339 "xmlNewTextWriterPushParser : error at xmlOutputBufferCreateIO!\n");
343 ret = xmlNewTextWriter(out);
345 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
346 "xmlNewTextWriterPushParser : error at xmlNewTextWriter!\n");
347 xmlOutputBufferClose(out);
357 * xmlNewTextWriterDoc:
358 * @doc: address of a xmlDocPtr to hold the new XML document tree
359 * @compression: compress the output?
361 * Create a new xmlNewTextWriter structure with @*doc as output
363 * Returns the new xmlTextWriterPtr or NULL in case of error
366 xmlNewTextWriterDoc(xmlDocPtr * doc, int compression)
368 xmlTextWriterPtr ret;
369 xmlSAXHandler saxHandler;
370 xmlParserCtxtPtr ctxt;
372 memset(&saxHandler, '\0', sizeof(saxHandler));
373 xmlSAX2InitDefaultSAXHandler(&saxHandler, 1);
374 saxHandler.startDocument = xmlTextWriterStartDocumentCallback;
375 saxHandler.startElement = xmlSAX2StartElement;
376 saxHandler.endElement = xmlSAX2EndElement;
378 ctxt = xmlCreatePushParserCtxt(&saxHandler, NULL, NULL, 0, NULL);
380 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
381 "xmlNewTextWriterDoc : error at xmlCreatePushParserCtxt!\n");
385 * For some reason this seems to completely break if node names
390 ctxt->myDoc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION);
391 if (ctxt->myDoc == NULL) {
392 xmlFreeParserCtxt(ctxt);
393 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
394 "xmlNewTextWriterDoc : error at xmlNewDoc!\n");
398 ret = xmlNewTextWriterPushParser(ctxt, compression);
400 xmlFreeDoc(ctxt->myDoc);
401 xmlFreeParserCtxt(ctxt);
402 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
403 "xmlNewTextWriterDoc : error at xmlNewTextWriterPushParser!\n");
407 xmlSetDocCompressMode(ctxt->myDoc, compression);
411 ret->no_doc_free = 1;
418 * xmlNewTextWriterTree:
420 * @node: xmlNodePtr or NULL for doc->children
421 * @compression: compress the output?
423 * Create a new xmlNewTextWriter structure with @doc as output
426 * Returns the new xmlTextWriterPtr or NULL in case of error
429 xmlNewTextWriterTree(xmlDocPtr doc, xmlNodePtr node, int compression)
431 xmlTextWriterPtr ret;
432 xmlSAXHandler saxHandler;
433 xmlParserCtxtPtr ctxt;
436 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
437 "xmlNewTextWriterTree : invalid document tree!\n");
441 memset(&saxHandler, '\0', sizeof(saxHandler));
442 xmlSAX2InitDefaultSAXHandler(&saxHandler, 1);
443 saxHandler.startDocument = xmlTextWriterStartDocumentCallback;
444 saxHandler.startElement = xmlSAX2StartElement;
445 saxHandler.endElement = xmlSAX2EndElement;
447 ctxt = xmlCreatePushParserCtxt(&saxHandler, NULL, NULL, 0, NULL);
449 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
450 "xmlNewTextWriterDoc : error at xmlCreatePushParserCtxt!\n");
454 * For some reason this seems to completely break if node names
459 ret = xmlNewTextWriterPushParser(ctxt, compression);
461 xmlFreeParserCtxt(ctxt);
462 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
463 "xmlNewTextWriterDoc : error at xmlNewTextWriterPushParser!\n");
469 ret->no_doc_free = 1;
471 xmlSetDocCompressMode(doc, compression);
478 * @writer: the xmlTextWriterPtr
480 * Deallocate all the resources associated to the writer
483 xmlFreeTextWriter(xmlTextWriterPtr writer)
488 if (writer->out != NULL)
489 xmlOutputBufferClose(writer->out);
491 if (writer->nodes != NULL)
492 xmlListDelete(writer->nodes);
494 if (writer->nsstack != NULL)
495 xmlListDelete(writer->nsstack);
497 if (writer->ctxt != NULL) {
498 if ((writer->ctxt->myDoc != NULL) && (writer->no_doc_free == 0)) {
499 xmlFreeDoc(writer->ctxt->myDoc);
500 writer->ctxt->myDoc = NULL;
502 xmlFreeParserCtxt(writer->ctxt);
505 if (writer->doc != NULL)
506 xmlFreeDoc(writer->doc);
508 if (writer->ichar != NULL)
509 xmlFree(writer->ichar);
514 * xmlTextWriterStartDocument:
515 * @writer: the xmlTextWriterPtr
516 * @version: the xml version ("1.0") or NULL for default ("1.0")
517 * @encoding: the encoding or NULL for default
518 * @standalone: "yes" or "no" or NULL for default
520 * Start a new xml document
522 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
525 xmlTextWriterStartDocument(xmlTextWriterPtr writer, const char *version,
526 const char *encoding, const char *standalone)
531 xmlCharEncodingHandlerPtr encoder;
533 if ((writer == NULL) || (writer->out == NULL)) {
534 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
535 "xmlTextWriterStartDocument : invalid writer!\n");
539 lk = xmlListFront(writer->nodes);
540 if ((lk != NULL) && (xmlLinkGetData(lk) != NULL)) {
541 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
542 "xmlTextWriterStartDocument : not allowed in this context!\n");
547 if (encoding != NULL) {
548 encoder = xmlFindCharEncodingHandler(encoding);
549 if (encoder == NULL) {
550 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
551 "xmlTextWriterStartDocument : out of memory!\n");
556 writer->out->encoder = encoder;
557 if (encoder != NULL) {
558 if (writer->out->conv == NULL) {
559 writer->out->conv = xmlBufCreateSize(4000);
561 xmlCharEncOutput(writer->out, 1);
562 if ((writer->doc != NULL) && (writer->doc->encoding == NULL))
563 writer->doc->encoding = xmlStrdup((xmlChar *)writer->out->encoder->name);
565 writer->out->conv = NULL;
568 count = xmlOutputBufferWriteString(writer->out, "<?xml version=");
572 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
577 count = xmlOutputBufferWriteString(writer->out, version);
579 count = xmlOutputBufferWriteString(writer->out, "1.0");
583 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
587 if (writer->out->encoder != 0) {
588 count = xmlOutputBufferWriteString(writer->out, " encoding=");
592 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
597 xmlOutputBufferWriteString(writer->out,
598 writer->out->encoder->name);
602 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
608 if (standalone != 0) {
609 count = xmlOutputBufferWriteString(writer->out, " standalone=");
613 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
617 count = xmlOutputBufferWriteString(writer->out, standalone);
621 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
627 count = xmlOutputBufferWriteString(writer->out, "?>\n");
636 * xmlTextWriterEndDocument:
637 * @writer: the xmlTextWriterPtr
639 * End an xml document. All open elements are closed, and
640 * the content is flushed to the output.
642 * Returns the bytes written or -1 in case of error
645 xmlTextWriterEndDocument(xmlTextWriterPtr writer)
650 xmlTextWriterStackEntry *p;
652 if (writer == NULL) {
653 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
654 "xmlTextWriterEndDocument : invalid writer!\n");
659 while ((lk = xmlListFront(writer->nodes)) != NULL) {
660 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
664 case XML_TEXTWRITER_NAME:
665 case XML_TEXTWRITER_ATTRIBUTE:
666 case XML_TEXTWRITER_TEXT:
667 count = xmlTextWriterEndElement(writer);
672 case XML_TEXTWRITER_PI:
673 case XML_TEXTWRITER_PI_TEXT:
674 count = xmlTextWriterEndPI(writer);
679 case XML_TEXTWRITER_CDATA:
680 count = xmlTextWriterEndCDATA(writer);
685 case XML_TEXTWRITER_DTD:
686 case XML_TEXTWRITER_DTD_TEXT:
687 case XML_TEXTWRITER_DTD_ELEM:
688 case XML_TEXTWRITER_DTD_ELEM_TEXT:
689 case XML_TEXTWRITER_DTD_ATTL:
690 case XML_TEXTWRITER_DTD_ATTL_TEXT:
691 case XML_TEXTWRITER_DTD_ENTY:
692 case XML_TEXTWRITER_DTD_ENTY_TEXT:
693 case XML_TEXTWRITER_DTD_PENT:
694 count = xmlTextWriterEndDTD(writer);
699 case XML_TEXTWRITER_COMMENT:
700 count = xmlTextWriterEndComment(writer);
710 if (!writer->indent) {
711 count = xmlOutputBufferWriteString(writer->out, "\n");
717 sum += xmlTextWriterFlush(writer);
723 * xmlTextWriterStartComment:
724 * @writer: the xmlTextWriterPtr
726 * Start an xml comment.
728 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
731 xmlTextWriterStartComment(xmlTextWriterPtr writer)
736 xmlTextWriterStackEntry *p;
738 if (writer == NULL) {
739 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
740 "xmlTextWriterStartComment : invalid writer!\n");
745 lk = xmlListFront(writer->nodes);
747 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
750 case XML_TEXTWRITER_TEXT:
751 case XML_TEXTWRITER_NONE:
753 case XML_TEXTWRITER_NAME:
754 /* Output namespace declarations */
755 count = xmlTextWriterOutputNSDecl(writer);
759 count = xmlOutputBufferWriteString(writer->out, ">");
763 if (writer->indent) {
765 xmlOutputBufferWriteString(writer->out, "\n");
770 p->state = XML_TEXTWRITER_TEXT;
778 p = (xmlTextWriterStackEntry *)
779 xmlMalloc(sizeof(xmlTextWriterStackEntry));
781 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
782 "xmlTextWriterStartElement : out of memory!\n");
787 p->state = XML_TEXTWRITER_COMMENT;
789 xmlListPushFront(writer->nodes, p);
791 if (writer->indent) {
792 count = xmlTextWriterWriteIndent(writer);
798 count = xmlOutputBufferWriteString(writer->out, "<!--");
807 * xmlTextWriterEndComment:
808 * @writer: the xmlTextWriterPtr
810 * End the current xml coment.
812 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
815 xmlTextWriterEndComment(xmlTextWriterPtr writer)
820 xmlTextWriterStackEntry *p;
822 if (writer == NULL) {
823 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
824 "xmlTextWriterEndComment : invalid writer!\n");
828 lk = xmlListFront(writer->nodes);
830 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
831 "xmlTextWriterEndComment : not allowed in this context!\n");
835 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
841 case XML_TEXTWRITER_COMMENT:
842 count = xmlOutputBufferWriteString(writer->out, "-->");
851 if (writer->indent) {
852 count = xmlOutputBufferWriteString(writer->out, "\n");
858 xmlListPopFront(writer->nodes);
863 * xmlTextWriterWriteFormatComment:
864 * @writer: the xmlTextWriterPtr
865 * @format: format string (see printf)
866 * @...: extra parameters for the format
868 * Write an xml comment.
870 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
873 xmlTextWriterWriteFormatComment(xmlTextWriterPtr writer,
874 const char *format, ...)
879 va_start(ap, format);
881 rc = xmlTextWriterWriteVFormatComment(writer, format, ap);
888 * xmlTextWriterWriteVFormatComment:
889 * @writer: the xmlTextWriterPtr
890 * @format: format string (see printf)
891 * @argptr: pointer to the first member of the variable argument list.
893 * Write an xml comment.
895 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
898 xmlTextWriterWriteVFormatComment(xmlTextWriterPtr writer,
899 const char *format, va_list argptr)
904 if (writer == NULL) {
905 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
906 "xmlTextWriterWriteVFormatComment : invalid writer!\n");
910 buf = xmlTextWriterVSprintf(format, argptr);
914 rc = xmlTextWriterWriteComment(writer, buf);
921 * xmlTextWriterWriteComment:
922 * @writer: the xmlTextWriterPtr
923 * @content: comment string
925 * Write an xml comment.
927 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
930 xmlTextWriterWriteComment(xmlTextWriterPtr writer, const xmlChar * content)
936 count = xmlTextWriterStartComment(writer);
940 count = xmlTextWriterWriteString(writer, content);
944 count = xmlTextWriterEndComment(writer);
953 * xmlTextWriterStartElement:
954 * @writer: the xmlTextWriterPtr
955 * @name: element name
957 * Start an xml element.
959 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
962 xmlTextWriterStartElement(xmlTextWriterPtr writer, const xmlChar * name)
967 xmlTextWriterStackEntry *p;
969 if ((writer == NULL) || (name == NULL) || (*name == '\0'))
973 lk = xmlListFront(writer->nodes);
975 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
978 case XML_TEXTWRITER_PI:
979 case XML_TEXTWRITER_PI_TEXT:
981 case XML_TEXTWRITER_NONE:
983 case XML_TEXTWRITER_ATTRIBUTE:
984 count = xmlTextWriterEndAttribute(writer);
989 case XML_TEXTWRITER_NAME:
990 /* Output namespace declarations */
991 count = xmlTextWriterOutputNSDecl(writer);
995 count = xmlOutputBufferWriteString(writer->out, ">");
1001 xmlOutputBufferWriteString(writer->out, "\n");
1002 p->state = XML_TEXTWRITER_TEXT;
1010 p = (xmlTextWriterStackEntry *)
1011 xmlMalloc(sizeof(xmlTextWriterStackEntry));
1013 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
1014 "xmlTextWriterStartElement : out of memory!\n");
1018 p->name = xmlStrdup(name);
1020 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
1021 "xmlTextWriterStartElement : out of memory!\n");
1025 p->state = XML_TEXTWRITER_NAME;
1027 xmlListPushFront(writer->nodes, p);
1029 if (writer->indent) {
1030 count = xmlTextWriterWriteIndent(writer);
1034 count = xmlOutputBufferWriteString(writer->out, "<");
1039 xmlOutputBufferWriteString(writer->out, (const char *) p->name);
1048 * xmlTextWriterStartElementNS:
1049 * @writer: the xmlTextWriterPtr
1050 * @prefix: namespace prefix or NULL
1051 * @name: element local name
1052 * @namespaceURI: namespace URI or NULL
1054 * Start an xml element with namespace support.
1056 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1059 xmlTextWriterStartElementNS(xmlTextWriterPtr writer,
1060 const xmlChar * prefix, const xmlChar * name,
1061 const xmlChar * namespaceURI)
1067 if ((writer == NULL) || (name == NULL) || (*name == '\0'))
1072 buf = xmlStrdup(prefix);
1073 buf = xmlStrcat(buf, BAD_CAST ":");
1075 buf = xmlStrcat(buf, name);
1078 count = xmlTextWriterStartElement(writer, buf);
1084 if (namespaceURI != 0) {
1085 xmlTextWriterNsStackEntry *p = (xmlTextWriterNsStackEntry *)
1086 xmlMalloc(sizeof(xmlTextWriterNsStackEntry));
1088 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
1089 "xmlTextWriterStartElementNS : out of memory!\n");
1093 buf = xmlStrdup(BAD_CAST "xmlns");
1095 buf = xmlStrcat(buf, BAD_CAST ":");
1096 buf = xmlStrcat(buf, prefix);
1100 p->uri = xmlStrdup(namespaceURI);
1102 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
1103 "xmlTextWriterStartElementNS : out of memory!\n");
1107 p->elem = xmlListFront(writer->nodes);
1109 xmlListPushFront(writer->nsstack, p);
1116 * xmlTextWriterEndElement:
1117 * @writer: the xmlTextWriterPtr
1119 * End the current xml element.
1121 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1124 xmlTextWriterEndElement(xmlTextWriterPtr writer)
1129 xmlTextWriterStackEntry *p;
1134 lk = xmlListFront(writer->nodes);
1136 xmlListDelete(writer->nsstack);
1137 writer->nsstack = NULL;
1141 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1143 xmlListDelete(writer->nsstack);
1144 writer->nsstack = NULL;
1150 case XML_TEXTWRITER_ATTRIBUTE:
1151 count = xmlTextWriterEndAttribute(writer);
1153 xmlListDelete(writer->nsstack);
1154 writer->nsstack = NULL;
1159 case XML_TEXTWRITER_NAME:
1160 /* Output namespace declarations */
1161 count = xmlTextWriterOutputNSDecl(writer);
1166 if (writer->indent) /* next element needs indent */
1167 writer->doindent = 1;
1168 count = xmlOutputBufferWriteString(writer->out, "/>");
1173 case XML_TEXTWRITER_TEXT:
1174 if ((writer->indent) && (writer->doindent)) {
1175 count = xmlTextWriterWriteIndent(writer);
1177 writer->doindent = 1;
1179 writer->doindent = 1;
1180 count = xmlOutputBufferWriteString(writer->out, "</");
1184 count = xmlOutputBufferWriteString(writer->out,
1185 (const char *) p->name);
1189 count = xmlOutputBufferWriteString(writer->out, ">");
1198 if (writer->indent) {
1199 count = xmlOutputBufferWriteString(writer->out, "\n");
1203 xmlListPopFront(writer->nodes);
1208 * xmlTextWriterFullEndElement:
1209 * @writer: the xmlTextWriterPtr
1211 * End the current xml element. Writes an end tag even if the element is empty
1213 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1216 xmlTextWriterFullEndElement(xmlTextWriterPtr writer)
1221 xmlTextWriterStackEntry *p;
1226 lk = xmlListFront(writer->nodes);
1230 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1236 case XML_TEXTWRITER_ATTRIBUTE:
1237 count = xmlTextWriterEndAttribute(writer);
1242 case XML_TEXTWRITER_NAME:
1243 /* Output namespace declarations */
1244 count = xmlTextWriterOutputNSDecl(writer);
1249 count = xmlOutputBufferWriteString(writer->out, ">");
1254 writer->doindent = 0;
1256 case XML_TEXTWRITER_TEXT:
1257 if ((writer->indent) && (writer->doindent)) {
1258 count = xmlTextWriterWriteIndent(writer);
1260 writer->doindent = 1;
1262 writer->doindent = 1;
1263 count = xmlOutputBufferWriteString(writer->out, "</");
1267 count = xmlOutputBufferWriteString(writer->out,
1268 (const char *) p->name);
1272 count = xmlOutputBufferWriteString(writer->out, ">");
1281 if (writer->indent) {
1282 count = xmlOutputBufferWriteString(writer->out, "\n");
1286 xmlListPopFront(writer->nodes);
1291 * xmlTextWriterWriteFormatRaw:
1292 * @writer: the xmlTextWriterPtr
1293 * @format: format string (see printf)
1294 * @...: extra parameters for the format
1296 * Write a formatted raw xml text.
1298 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1301 xmlTextWriterWriteFormatRaw(xmlTextWriterPtr writer, const char *format,
1307 va_start(ap, format);
1309 rc = xmlTextWriterWriteVFormatRaw(writer, format, ap);
1316 * xmlTextWriterWriteVFormatRaw:
1317 * @writer: the xmlTextWriterPtr
1318 * @format: format string (see printf)
1319 * @argptr: pointer to the first member of the variable argument list.
1321 * Write a formatted raw xml text.
1323 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1326 xmlTextWriterWriteVFormatRaw(xmlTextWriterPtr writer, const char *format,
1335 buf = xmlTextWriterVSprintf(format, argptr);
1339 rc = xmlTextWriterWriteRaw(writer, buf);
1346 * xmlTextWriterWriteRawLen:
1347 * @writer: the xmlTextWriterPtr
1348 * @content: text string
1349 * @len: length of the text string
1351 * Write an xml text.
1352 * TODO: what about entities and special chars??
1354 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1357 xmlTextWriterWriteRawLen(xmlTextWriterPtr writer, const xmlChar * content,
1363 xmlTextWriterStackEntry *p;
1365 if (writer == NULL) {
1366 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
1367 "xmlTextWriterWriteRawLen : invalid writer!\n");
1371 if ((content == NULL) || (len < 0)) {
1372 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
1373 "xmlTextWriterWriteRawLen : invalid content!\n");
1378 lk = xmlListFront(writer->nodes);
1380 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1381 count = xmlTextWriterHandleStateDependencies(writer, p);
1388 writer->doindent = 0;
1390 if (content != NULL) {
1392 xmlOutputBufferWrite(writer->out, len, (const char *) content);
1402 * xmlTextWriterWriteRaw:
1403 * @writer: the xmlTextWriterPtr
1404 * @content: text string
1406 * Write a raw xml text.
1408 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1411 xmlTextWriterWriteRaw(xmlTextWriterPtr writer, const xmlChar * content)
1413 return xmlTextWriterWriteRawLen(writer, content, xmlStrlen(content));
1417 * xmlTextWriterWriteFormatString:
1418 * @writer: the xmlTextWriterPtr
1419 * @format: format string (see printf)
1420 * @...: extra parameters for the format
1422 * Write a formatted xml text.
1424 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1427 xmlTextWriterWriteFormatString(xmlTextWriterPtr writer, const char *format,
1433 if ((writer == NULL) || (format == NULL))
1436 va_start(ap, format);
1438 rc = xmlTextWriterWriteVFormatString(writer, format, ap);
1445 * xmlTextWriterWriteVFormatString:
1446 * @writer: the xmlTextWriterPtr
1447 * @format: format string (see printf)
1448 * @argptr: pointer to the first member of the variable argument list.
1450 * Write a formatted xml text.
1452 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1455 xmlTextWriterWriteVFormatString(xmlTextWriterPtr writer,
1456 const char *format, va_list argptr)
1461 if ((writer == NULL) || (format == NULL))
1464 buf = xmlTextWriterVSprintf(format, argptr);
1468 rc = xmlTextWriterWriteString(writer, buf);
1475 * xmlTextWriterWriteString:
1476 * @writer: the xmlTextWriterPtr
1477 * @content: text string
1479 * Write an xml text.
1481 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1484 xmlTextWriterWriteString(xmlTextWriterPtr writer, const xmlChar * content)
1489 xmlTextWriterStackEntry *p;
1492 if ((writer == NULL) || (content == NULL))
1496 buf = (xmlChar *) content;
1497 lk = xmlListFront(writer->nodes);
1499 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1502 case XML_TEXTWRITER_NAME:
1503 case XML_TEXTWRITER_TEXT:
1506 xmlOutputBufferWriteEscape(writer->out, content, NULL);
1508 buf = xmlEncodeSpecialChars(NULL, content);
1510 case XML_TEXTWRITER_ATTRIBUTE:
1512 xmlBufAttrSerializeTxtContent(writer->out->buffer,
1513 writer->doc, NULL, content);
1522 count = xmlTextWriterWriteRaw(writer, buf);
1524 if (buf != content) /* buf was allocated by us, so free it */
1536 * xmlOutputBufferWriteBase64:
1537 * @out: the xmlOutputBufferPtr
1538 * @data: binary data
1539 * @len: the number of bytes to encode
1541 * Write base64 encoded data to an xmlOutputBuffer.
1542 * Adapted from John Walker's base64.c (http://www.fourmilab.ch/).
1544 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1547 xmlOutputBufferWriteBase64(xmlOutputBufferPtr out, int len,
1548 const unsigned char *data)
1550 static unsigned char dtable[64] =
1551 {'A','B','C','D','E','F','G','H','I','J','K','L','M',
1552 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
1553 'a','b','c','d','e','f','g','h','i','j','k','l','m',
1554 'n','o','p','q','r','s','t','u','v','w','x','y','z',
1555 '0','1','2','3','4','5','6','7','8','9','+','/'};
1562 if ((out == NULL) || (len < 0) || (data == NULL))
1570 unsigned char igroup[3];
1571 unsigned char ogroup[4];
1575 igroup[0] = igroup[1] = igroup[2] = 0;
1576 for (n = 0; n < 3 && i < len; n++, i++) {
1578 igroup[n] = (unsigned char) c;
1582 ogroup[0] = dtable[igroup[0] >> 2];
1583 ogroup[1] = dtable[((igroup[0] & 3) << 4) | (igroup[1] >> 4)];
1585 dtable[((igroup[1] & 0xF) << 2) | (igroup[2] >> 6)];
1586 ogroup[3] = dtable[igroup[2] & 0x3F];
1595 if (linelen >= B64LINELEN) {
1596 count = xmlOutputBufferWrite(out, 2, B64CRLF);
1602 count = xmlOutputBufferWrite(out, 4, (const char *) ogroup);
1618 * xmlTextWriterWriteBase64:
1619 * @writer: the xmlTextWriterPtr
1620 * @data: binary data
1621 * @start: the position within the data of the first byte to encode
1622 * @len: the number of bytes to encode
1624 * Write an base64 encoded xml text.
1626 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1629 xmlTextWriterWriteBase64(xmlTextWriterPtr writer, const char *data,
1635 xmlTextWriterStackEntry *p;
1637 if ((writer == NULL) || (data == NULL) || (start < 0) || (len < 0))
1641 lk = xmlListFront(writer->nodes);
1643 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1645 count = xmlTextWriterHandleStateDependencies(writer, p);
1653 writer->doindent = 0;
1656 xmlOutputBufferWriteBase64(writer->out, len,
1657 (unsigned char *) data + start);
1666 * xmlOutputBufferWriteBinHex:
1667 * @out: the xmlOutputBufferPtr
1668 * @data: binary data
1669 * @len: the number of bytes to encode
1671 * Write hqx encoded data to an xmlOutputBuffer.
1674 * Returns the bytes written (may be 0 because of buffering)
1675 * or -1 in case of error
1678 xmlOutputBufferWriteBinHex(xmlOutputBufferPtr out,
1679 int len, const unsigned char *data)
1683 static char hex[16] =
1684 {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
1687 if ((out == NULL) || (data == NULL) || (len < 0)) {
1692 for (i = 0; i < len; i++) {
1694 xmlOutputBufferWrite(out, 1,
1695 (const char *) &hex[data[i] >> 4]);
1700 xmlOutputBufferWrite(out, 1,
1701 (const char *) &hex[data[i] & 0xF]);
1711 * xmlTextWriterWriteBinHex:
1712 * @writer: the xmlTextWriterPtr
1713 * @data: binary data
1714 * @start: the position within the data of the first byte to encode
1715 * @len: the number of bytes to encode
1717 * Write a BinHex encoded xml text.
1719 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1722 xmlTextWriterWriteBinHex(xmlTextWriterPtr writer, const char *data,
1728 xmlTextWriterStackEntry *p;
1730 if ((writer == NULL) || (data == NULL) || (start < 0) || (len < 0))
1734 lk = xmlListFront(writer->nodes);
1736 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1738 count = xmlTextWriterHandleStateDependencies(writer, p);
1746 writer->doindent = 0;
1749 xmlOutputBufferWriteBinHex(writer->out, len,
1750 (unsigned char *) data + start);
1759 * xmlTextWriterStartAttribute:
1760 * @writer: the xmlTextWriterPtr
1761 * @name: element name
1763 * Start an xml attribute.
1765 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1768 xmlTextWriterStartAttribute(xmlTextWriterPtr writer, const xmlChar * name)
1773 xmlTextWriterStackEntry *p;
1775 if ((writer == NULL) || (name == NULL) || (*name == '\0'))
1779 lk = xmlListFront(writer->nodes);
1783 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1788 case XML_TEXTWRITER_ATTRIBUTE:
1789 count = xmlTextWriterEndAttribute(writer);
1794 case XML_TEXTWRITER_NAME:
1795 count = xmlOutputBufferWriteString(writer->out, " ");
1800 xmlOutputBufferWriteString(writer->out,
1801 (const char *) name);
1805 count = xmlOutputBufferWriteString(writer->out, "=");
1809 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
1813 p->state = XML_TEXTWRITER_ATTRIBUTE;
1823 * xmlTextWriterStartAttributeNS:
1824 * @writer: the xmlTextWriterPtr
1825 * @prefix: namespace prefix or NULL
1826 * @name: element local name
1827 * @namespaceURI: namespace URI or NULL
1829 * Start an xml attribute with namespace support.
1831 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1834 xmlTextWriterStartAttributeNS(xmlTextWriterPtr writer,
1835 const xmlChar * prefix, const xmlChar * name,
1836 const xmlChar * namespaceURI)
1841 xmlTextWriterNsStackEntry *p;
1843 if ((writer == NULL) || (name == NULL) || (*name == '\0'))
1846 /* Handle namespace first in case of error */
1847 if (namespaceURI != 0) {
1848 xmlTextWriterNsStackEntry nsentry, *curns;
1850 buf = xmlStrdup(BAD_CAST "xmlns");
1852 buf = xmlStrcat(buf, BAD_CAST ":");
1853 buf = xmlStrcat(buf, prefix);
1856 nsentry.prefix = buf;
1857 nsentry.uri = (xmlChar *)namespaceURI;
1858 nsentry.elem = xmlListFront(writer->nodes);
1860 curns = (xmlTextWriterNsStackEntry *)xmlListSearch(writer->nsstack,
1862 if ((curns != NULL)) {
1864 if (xmlStrcmp(curns->uri, namespaceURI) == 0) {
1865 /* Namespace already defined on element skip */
1868 /* Prefix mismatch so error out */
1873 /* Do not add namespace decl to list - it is already there */
1875 p = (xmlTextWriterNsStackEntry *)
1876 xmlMalloc(sizeof(xmlTextWriterNsStackEntry));
1878 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
1879 "xmlTextWriterStartAttributeNS : out of memory!\n");
1884 p->uri = xmlStrdup(namespaceURI);
1886 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
1887 "xmlTextWriterStartAttributeNS : out of memory!\n");
1891 p->elem = xmlListFront(writer->nodes);
1893 xmlListPushFront(writer->nsstack, p);
1899 buf = xmlStrdup(prefix);
1900 buf = xmlStrcat(buf, BAD_CAST ":");
1902 buf = xmlStrcat(buf, name);
1905 count = xmlTextWriterStartAttribute(writer, buf);
1915 * xmlTextWriterEndAttribute:
1916 * @writer: the xmlTextWriterPtr
1918 * End the current xml element.
1920 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1923 xmlTextWriterEndAttribute(xmlTextWriterPtr writer)
1928 xmlTextWriterStackEntry *p;
1933 lk = xmlListFront(writer->nodes);
1938 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
1945 case XML_TEXTWRITER_ATTRIBUTE:
1946 p->state = XML_TEXTWRITER_NAME;
1948 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
1962 * xmlTextWriterWriteFormatAttribute:
1963 * @writer: the xmlTextWriterPtr
1964 * @name: attribute name
1965 * @format: format string (see printf)
1966 * @...: extra parameters for the format
1968 * Write a formatted xml attribute.
1970 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1973 xmlTextWriterWriteFormatAttribute(xmlTextWriterPtr writer,
1974 const xmlChar * name, const char *format,
1980 va_start(ap, format);
1982 rc = xmlTextWriterWriteVFormatAttribute(writer, name, format, ap);
1989 * xmlTextWriterWriteVFormatAttribute:
1990 * @writer: the xmlTextWriterPtr
1991 * @name: attribute name
1992 * @format: format string (see printf)
1993 * @argptr: pointer to the first member of the variable argument list.
1995 * Write a formatted xml attribute.
1997 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2000 xmlTextWriterWriteVFormatAttribute(xmlTextWriterPtr writer,
2001 const xmlChar * name,
2002 const char *format, va_list argptr)
2010 buf = xmlTextWriterVSprintf(format, argptr);
2014 rc = xmlTextWriterWriteAttribute(writer, name, buf);
2021 * xmlTextWriterWriteAttribute:
2022 * @writer: the xmlTextWriterPtr
2023 * @name: attribute name
2024 * @content: attribute content
2026 * Write an xml attribute.
2028 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2031 xmlTextWriterWriteAttribute(xmlTextWriterPtr writer, const xmlChar * name,
2032 const xmlChar * content)
2038 count = xmlTextWriterStartAttribute(writer, name);
2042 count = xmlTextWriterWriteString(writer, content);
2046 count = xmlTextWriterEndAttribute(writer);
2055 * xmlTextWriterWriteFormatAttributeNS:
2056 * @writer: the xmlTextWriterPtr
2057 * @prefix: namespace prefix
2058 * @name: attribute local name
2059 * @namespaceURI: namespace URI
2060 * @format: format string (see printf)
2061 * @...: extra parameters for the format
2063 * Write a formatted xml attribute.with namespace support
2065 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2068 xmlTextWriterWriteFormatAttributeNS(xmlTextWriterPtr writer,
2069 const xmlChar * prefix,
2070 const xmlChar * name,
2071 const xmlChar * namespaceURI,
2072 const char *format, ...)
2077 va_start(ap, format);
2079 rc = xmlTextWriterWriteVFormatAttributeNS(writer, prefix, name,
2080 namespaceURI, format, ap);
2087 * xmlTextWriterWriteVFormatAttributeNS:
2088 * @writer: the xmlTextWriterPtr
2089 * @prefix: namespace prefix
2090 * @name: attribute local name
2091 * @namespaceURI: namespace URI
2092 * @format: format string (see printf)
2093 * @argptr: pointer to the first member of the variable argument list.
2095 * Write a formatted xml attribute.with namespace support
2097 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2100 xmlTextWriterWriteVFormatAttributeNS(xmlTextWriterPtr writer,
2101 const xmlChar * prefix,
2102 const xmlChar * name,
2103 const xmlChar * namespaceURI,
2104 const char *format, va_list argptr)
2112 buf = xmlTextWriterVSprintf(format, argptr);
2116 rc = xmlTextWriterWriteAttributeNS(writer, prefix, name, namespaceURI,
2124 * xmlTextWriterWriteAttributeNS:
2125 * @writer: the xmlTextWriterPtr
2126 * @prefix: namespace prefix
2127 * @name: attribute local name
2128 * @namespaceURI: namespace URI
2129 * @content: attribute content
2131 * Write an xml attribute.
2133 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2136 xmlTextWriterWriteAttributeNS(xmlTextWriterPtr writer,
2137 const xmlChar * prefix, const xmlChar * name,
2138 const xmlChar * namespaceURI,
2139 const xmlChar * content)
2144 if ((writer == NULL) || (name == NULL) || (*name == '\0'))
2148 count = xmlTextWriterStartAttributeNS(writer, prefix, name, namespaceURI);
2152 count = xmlTextWriterWriteString(writer, content);
2156 count = xmlTextWriterEndAttribute(writer);
2165 * xmlTextWriterWriteFormatElement:
2166 * @writer: the xmlTextWriterPtr
2167 * @name: element name
2168 * @format: format string (see printf)
2169 * @...: extra parameters for the format
2171 * Write a formatted xml element.
2173 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2176 xmlTextWriterWriteFormatElement(xmlTextWriterPtr writer,
2177 const xmlChar * name, const char *format,
2183 va_start(ap, format);
2185 rc = xmlTextWriterWriteVFormatElement(writer, name, format, ap);
2192 * xmlTextWriterWriteVFormatElement:
2193 * @writer: the xmlTextWriterPtr
2194 * @name: element name
2195 * @format: format string (see printf)
2196 * @argptr: pointer to the first member of the variable argument list.
2198 * Write a formatted xml element.
2200 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2203 xmlTextWriterWriteVFormatElement(xmlTextWriterPtr writer,
2204 const xmlChar * name, const char *format,
2213 buf = xmlTextWriterVSprintf(format, argptr);
2217 rc = xmlTextWriterWriteElement(writer, name, buf);
2224 * xmlTextWriterWriteElement:
2225 * @writer: the xmlTextWriterPtr
2226 * @name: element name
2227 * @content: element content
2229 * Write an xml element.
2231 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2234 xmlTextWriterWriteElement(xmlTextWriterPtr writer, const xmlChar * name,
2235 const xmlChar * content)
2241 count = xmlTextWriterStartElement(writer, name);
2245 if (content != NULL) {
2246 count = xmlTextWriterWriteString(writer, content);
2251 count = xmlTextWriterEndElement(writer);
2260 * xmlTextWriterWriteFormatElementNS:
2261 * @writer: the xmlTextWriterPtr
2262 * @prefix: namespace prefix
2263 * @name: element local name
2264 * @namespaceURI: namespace URI
2265 * @format: format string (see printf)
2266 * @...: extra parameters for the format
2268 * Write a formatted xml element with namespace support.
2270 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2273 xmlTextWriterWriteFormatElementNS(xmlTextWriterPtr writer,
2274 const xmlChar * prefix,
2275 const xmlChar * name,
2276 const xmlChar * namespaceURI,
2277 const char *format, ...)
2282 va_start(ap, format);
2284 rc = xmlTextWriterWriteVFormatElementNS(writer, prefix, name,
2285 namespaceURI, format, ap);
2292 * xmlTextWriterWriteVFormatElementNS:
2293 * @writer: the xmlTextWriterPtr
2294 * @prefix: namespace prefix
2295 * @name: element local name
2296 * @namespaceURI: namespace URI
2297 * @format: format string (see printf)
2298 * @argptr: pointer to the first member of the variable argument list.
2300 * Write a formatted xml element with namespace support.
2302 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2305 xmlTextWriterWriteVFormatElementNS(xmlTextWriterPtr writer,
2306 const xmlChar * prefix,
2307 const xmlChar * name,
2308 const xmlChar * namespaceURI,
2309 const char *format, va_list argptr)
2317 buf = xmlTextWriterVSprintf(format, argptr);
2321 rc = xmlTextWriterWriteElementNS(writer, prefix, name, namespaceURI,
2329 * xmlTextWriterWriteElementNS:
2330 * @writer: the xmlTextWriterPtr
2331 * @prefix: namespace prefix
2332 * @name: element local name
2333 * @namespaceURI: namespace URI
2334 * @content: element content
2336 * Write an xml element with namespace support.
2338 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2341 xmlTextWriterWriteElementNS(xmlTextWriterPtr writer,
2342 const xmlChar * prefix, const xmlChar * name,
2343 const xmlChar * namespaceURI,
2344 const xmlChar * content)
2349 if ((writer == NULL) || (name == NULL) || (*name == '\0'))
2354 xmlTextWriterStartElementNS(writer, prefix, name, namespaceURI);
2358 count = xmlTextWriterWriteString(writer, content);
2362 count = xmlTextWriterEndElement(writer);
2371 * xmlTextWriterStartPI:
2372 * @writer: the xmlTextWriterPtr
2373 * @target: PI target
2377 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2380 xmlTextWriterStartPI(xmlTextWriterPtr writer, const xmlChar * target)
2385 xmlTextWriterStackEntry *p;
2387 if ((writer == NULL) || (target == NULL) || (*target == '\0'))
2390 if (xmlStrcasecmp(target, (const xmlChar *) "xml") == 0) {
2391 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
2392 "xmlTextWriterStartPI : target name [Xx][Mm][Ll] is reserved for xml standardization!\n");
2397 lk = xmlListFront(writer->nodes);
2399 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
2402 case XML_TEXTWRITER_ATTRIBUTE:
2403 count = xmlTextWriterEndAttribute(writer);
2408 case XML_TEXTWRITER_NAME:
2409 /* Output namespace declarations */
2410 count = xmlTextWriterOutputNSDecl(writer);
2414 count = xmlOutputBufferWriteString(writer->out, ">");
2418 p->state = XML_TEXTWRITER_TEXT;
2420 case XML_TEXTWRITER_NONE:
2421 case XML_TEXTWRITER_TEXT:
2422 case XML_TEXTWRITER_DTD:
2424 case XML_TEXTWRITER_PI:
2425 case XML_TEXTWRITER_PI_TEXT:
2426 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
2427 "xmlTextWriterStartPI : nested PI!\n");
2435 p = (xmlTextWriterStackEntry *)
2436 xmlMalloc(sizeof(xmlTextWriterStackEntry));
2438 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
2439 "xmlTextWriterStartPI : out of memory!\n");
2443 p->name = xmlStrdup(target);
2445 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
2446 "xmlTextWriterStartPI : out of memory!\n");
2450 p->state = XML_TEXTWRITER_PI;
2452 xmlListPushFront(writer->nodes, p);
2454 count = xmlOutputBufferWriteString(writer->out, "<?");
2459 xmlOutputBufferWriteString(writer->out, (const char *) p->name);
2468 * xmlTextWriterEndPI:
2469 * @writer: the xmlTextWriterPtr
2471 * End the current xml PI.
2473 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2476 xmlTextWriterEndPI(xmlTextWriterPtr writer)
2481 xmlTextWriterStackEntry *p;
2486 lk = xmlListFront(writer->nodes);
2490 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
2496 case XML_TEXTWRITER_PI:
2497 case XML_TEXTWRITER_PI_TEXT:
2498 count = xmlOutputBufferWriteString(writer->out, "?>");
2507 if (writer->indent) {
2508 count = xmlOutputBufferWriteString(writer->out, "\n");
2514 xmlListPopFront(writer->nodes);
2519 * xmlTextWriterWriteFormatPI:
2520 * @writer: the xmlTextWriterPtr
2521 * @target: PI target
2522 * @format: format string (see printf)
2523 * @...: extra parameters for the format
2525 * Write a formatted PI.
2527 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2530 xmlTextWriterWriteFormatPI(xmlTextWriterPtr writer, const xmlChar * target,
2531 const char *format, ...)
2536 va_start(ap, format);
2538 rc = xmlTextWriterWriteVFormatPI(writer, target, format, ap);
2545 * xmlTextWriterWriteVFormatPI:
2546 * @writer: the xmlTextWriterPtr
2547 * @target: PI target
2548 * @format: format string (see printf)
2549 * @argptr: pointer to the first member of the variable argument list.
2551 * Write a formatted xml PI.
2553 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2556 xmlTextWriterWriteVFormatPI(xmlTextWriterPtr writer,
2557 const xmlChar * target, const char *format,
2566 buf = xmlTextWriterVSprintf(format, argptr);
2570 rc = xmlTextWriterWritePI(writer, target, buf);
2577 * xmlTextWriterWritePI:
2578 * @writer: the xmlTextWriterPtr
2579 * @target: PI target
2580 * @content: PI content
2584 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2587 xmlTextWriterWritePI(xmlTextWriterPtr writer, const xmlChar * target,
2588 const xmlChar * content)
2594 count = xmlTextWriterStartPI(writer, target);
2599 count = xmlTextWriterWriteString(writer, content);
2604 count = xmlTextWriterEndPI(writer);
2613 * xmlTextWriterStartCDATA:
2614 * @writer: the xmlTextWriterPtr
2616 * Start an xml CDATA section.
2618 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2621 xmlTextWriterStartCDATA(xmlTextWriterPtr writer)
2626 xmlTextWriterStackEntry *p;
2632 lk = xmlListFront(writer->nodes);
2634 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
2637 case XML_TEXTWRITER_NONE:
2638 case XML_TEXTWRITER_TEXT:
2639 case XML_TEXTWRITER_PI:
2640 case XML_TEXTWRITER_PI_TEXT:
2642 case XML_TEXTWRITER_ATTRIBUTE:
2643 count = xmlTextWriterEndAttribute(writer);
2648 case XML_TEXTWRITER_NAME:
2649 /* Output namespace declarations */
2650 count = xmlTextWriterOutputNSDecl(writer);
2654 count = xmlOutputBufferWriteString(writer->out, ">");
2658 p->state = XML_TEXTWRITER_TEXT;
2660 case XML_TEXTWRITER_CDATA:
2661 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
2662 "xmlTextWriterStartCDATA : CDATA not allowed in this context!\n");
2670 p = (xmlTextWriterStackEntry *)
2671 xmlMalloc(sizeof(xmlTextWriterStackEntry));
2673 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
2674 "xmlTextWriterStartCDATA : out of memory!\n");
2679 p->state = XML_TEXTWRITER_CDATA;
2681 xmlListPushFront(writer->nodes, p);
2683 count = xmlOutputBufferWriteString(writer->out, "<![CDATA[");
2692 * xmlTextWriterEndCDATA:
2693 * @writer: the xmlTextWriterPtr
2695 * End an xml CDATA section.
2697 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2700 xmlTextWriterEndCDATA(xmlTextWriterPtr writer)
2705 xmlTextWriterStackEntry *p;
2710 lk = xmlListFront(writer->nodes);
2714 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
2720 case XML_TEXTWRITER_CDATA:
2721 count = xmlOutputBufferWriteString(writer->out, "]]>");
2730 xmlListPopFront(writer->nodes);
2735 * xmlTextWriterWriteFormatCDATA:
2736 * @writer: the xmlTextWriterPtr
2737 * @format: format string (see printf)
2738 * @...: extra parameters for the format
2740 * Write a formatted xml CDATA.
2742 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2745 xmlTextWriterWriteFormatCDATA(xmlTextWriterPtr writer, const char *format,
2751 va_start(ap, format);
2753 rc = xmlTextWriterWriteVFormatCDATA(writer, format, ap);
2760 * xmlTextWriterWriteVFormatCDATA:
2761 * @writer: the xmlTextWriterPtr
2762 * @format: format string (see printf)
2763 * @argptr: pointer to the first member of the variable argument list.
2765 * Write a formatted xml CDATA.
2767 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2770 xmlTextWriterWriteVFormatCDATA(xmlTextWriterPtr writer, const char *format,
2779 buf = xmlTextWriterVSprintf(format, argptr);
2783 rc = xmlTextWriterWriteCDATA(writer, buf);
2790 * xmlTextWriterWriteCDATA:
2791 * @writer: the xmlTextWriterPtr
2792 * @content: CDATA content
2794 * Write an xml CDATA.
2796 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2799 xmlTextWriterWriteCDATA(xmlTextWriterPtr writer, const xmlChar * content)
2805 count = xmlTextWriterStartCDATA(writer);
2810 count = xmlTextWriterWriteString(writer, content);
2815 count = xmlTextWriterEndCDATA(writer);
2824 * xmlTextWriterStartDTD:
2825 * @writer: the xmlTextWriterPtr
2826 * @name: the name of the DTD
2827 * @pubid: the public identifier, which is an alternative to the system identifier
2828 * @sysid: the system identifier, which is the URI of the DTD
2832 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2835 xmlTextWriterStartDTD(xmlTextWriterPtr writer,
2836 const xmlChar * name,
2837 const xmlChar * pubid, const xmlChar * sysid)
2842 xmlTextWriterStackEntry *p;
2844 if (writer == NULL || name == NULL || *name == '\0')
2848 lk = xmlListFront(writer->nodes);
2849 if ((lk != NULL) && (xmlLinkGetData(lk) != NULL)) {
2850 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
2851 "xmlTextWriterStartDTD : DTD allowed only in prolog!\n");
2855 p = (xmlTextWriterStackEntry *)
2856 xmlMalloc(sizeof(xmlTextWriterStackEntry));
2858 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
2859 "xmlTextWriterStartDTD : out of memory!\n");
2863 p->name = xmlStrdup(name);
2865 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
2866 "xmlTextWriterStartDTD : out of memory!\n");
2870 p->state = XML_TEXTWRITER_DTD;
2872 xmlListPushFront(writer->nodes, p);
2874 count = xmlOutputBufferWriteString(writer->out, "<!DOCTYPE ");
2878 count = xmlOutputBufferWriteString(writer->out, (const char *) name);
2885 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
2886 "xmlTextWriterStartDTD : system identifier needed!\n");
2891 count = xmlOutputBufferWrite(writer->out, 1, "\n");
2893 count = xmlOutputBufferWrite(writer->out, 1, " ");
2898 count = xmlOutputBufferWriteString(writer->out, "PUBLIC ");
2903 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
2909 xmlOutputBufferWriteString(writer->out, (const char *) pubid);
2914 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
2923 count = xmlOutputBufferWrite(writer->out, 1, "\n");
2925 count = xmlOutputBufferWrite(writer->out, 1, " ");
2929 count = xmlOutputBufferWriteString(writer->out, "SYSTEM ");
2935 count = xmlOutputBufferWriteString(writer->out, "\n ");
2937 count = xmlOutputBufferWrite(writer->out, 1, " ");
2943 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
2949 xmlOutputBufferWriteString(writer->out, (const char *) sysid);
2954 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
2964 * xmlTextWriterEndDTD:
2965 * @writer: the xmlTextWriterPtr
2969 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2972 xmlTextWriterEndDTD(xmlTextWriterPtr writer)
2978 xmlTextWriterStackEntry *p;
2986 lk = xmlListFront(writer->nodes);
2989 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
2993 case XML_TEXTWRITER_DTD_TEXT:
2994 count = xmlOutputBufferWriteString(writer->out, "]");
2999 case XML_TEXTWRITER_DTD:
3000 count = xmlOutputBufferWriteString(writer->out, ">");
3002 if (writer->indent) {
3006 count = xmlOutputBufferWriteString(writer->out, "\n");
3009 xmlListPopFront(writer->nodes);
3011 case XML_TEXTWRITER_DTD_ELEM:
3012 case XML_TEXTWRITER_DTD_ELEM_TEXT:
3013 count = xmlTextWriterEndDTDElement(writer);
3015 case XML_TEXTWRITER_DTD_ATTL:
3016 case XML_TEXTWRITER_DTD_ATTL_TEXT:
3017 count = xmlTextWriterEndDTDAttlist(writer);
3019 case XML_TEXTWRITER_DTD_ENTY:
3020 case XML_TEXTWRITER_DTD_PENT:
3021 case XML_TEXTWRITER_DTD_ENTY_TEXT:
3022 count = xmlTextWriterEndDTDEntity(writer);
3024 case XML_TEXTWRITER_COMMENT:
3025 count = xmlTextWriterEndComment(writer);
3041 * xmlTextWriterWriteFormatDTD:
3042 * @writer: the xmlTextWriterPtr
3043 * @name: the name of the DTD
3044 * @pubid: the public identifier, which is an alternative to the system identifier
3045 * @sysid: the system identifier, which is the URI of the DTD
3046 * @format: format string (see printf)
3047 * @...: extra parameters for the format
3049 * Write a DTD with a formatted markup declarations part.
3051 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3054 xmlTextWriterWriteFormatDTD(xmlTextWriterPtr writer,
3055 const xmlChar * name,
3056 const xmlChar * pubid,
3057 const xmlChar * sysid, const char *format, ...)
3062 va_start(ap, format);
3064 rc = xmlTextWriterWriteVFormatDTD(writer, name, pubid, sysid, format,
3072 * xmlTextWriterWriteVFormatDTD:
3073 * @writer: the xmlTextWriterPtr
3074 * @name: the name of the DTD
3075 * @pubid: the public identifier, which is an alternative to the system identifier
3076 * @sysid: the system identifier, which is the URI of the DTD
3077 * @format: format string (see printf)
3078 * @argptr: pointer to the first member of the variable argument list.
3080 * Write a DTD with a formatted markup declarations part.
3082 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3085 xmlTextWriterWriteVFormatDTD(xmlTextWriterPtr writer,
3086 const xmlChar * name,
3087 const xmlChar * pubid,
3088 const xmlChar * sysid,
3089 const char *format, va_list argptr)
3097 buf = xmlTextWriterVSprintf(format, argptr);
3101 rc = xmlTextWriterWriteDTD(writer, name, pubid, sysid, buf);
3108 * xmlTextWriterWriteDTD:
3109 * @writer: the xmlTextWriterPtr
3110 * @name: the name of the DTD
3111 * @pubid: the public identifier, which is an alternative to the system identifier
3112 * @sysid: the system identifier, which is the URI of the DTD
3113 * @subset: string content of the DTD
3117 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3120 xmlTextWriterWriteDTD(xmlTextWriterPtr writer,
3121 const xmlChar * name,
3122 const xmlChar * pubid,
3123 const xmlChar * sysid, const xmlChar * subset)
3129 count = xmlTextWriterStartDTD(writer, name, pubid, sysid);
3134 count = xmlTextWriterWriteString(writer, subset);
3139 count = xmlTextWriterEndDTD(writer);
3148 * xmlTextWriterStartDTDElement:
3149 * @writer: the xmlTextWriterPtr
3150 * @name: the name of the DTD element
3152 * Start an xml DTD element.
3154 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3157 xmlTextWriterStartDTDElement(xmlTextWriterPtr writer, const xmlChar * name)
3162 xmlTextWriterStackEntry *p;
3164 if (writer == NULL || name == NULL || *name == '\0')
3168 lk = xmlListFront(writer->nodes);
3173 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3176 case XML_TEXTWRITER_DTD:
3177 count = xmlOutputBufferWriteString(writer->out, " [");
3181 if (writer->indent) {
3182 count = xmlOutputBufferWriteString(writer->out, "\n");
3187 p->state = XML_TEXTWRITER_DTD_TEXT;
3189 case XML_TEXTWRITER_DTD_TEXT:
3190 case XML_TEXTWRITER_NONE:
3197 p = (xmlTextWriterStackEntry *)
3198 xmlMalloc(sizeof(xmlTextWriterStackEntry));
3200 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
3201 "xmlTextWriterStartDTDElement : out of memory!\n");
3205 p->name = xmlStrdup(name);
3207 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
3208 "xmlTextWriterStartDTDElement : out of memory!\n");
3212 p->state = XML_TEXTWRITER_DTD_ELEM;
3214 xmlListPushFront(writer->nodes, p);
3216 if (writer->indent) {
3217 count = xmlTextWriterWriteIndent(writer);
3223 count = xmlOutputBufferWriteString(writer->out, "<!ELEMENT ");
3227 count = xmlOutputBufferWriteString(writer->out, (const char *) name);
3236 * xmlTextWriterEndDTDElement:
3237 * @writer: the xmlTextWriterPtr
3239 * End an xml DTD element.
3241 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3244 xmlTextWriterEndDTDElement(xmlTextWriterPtr writer)
3249 xmlTextWriterStackEntry *p;
3255 lk = xmlListFront(writer->nodes);
3259 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3264 case XML_TEXTWRITER_DTD_ELEM:
3265 case XML_TEXTWRITER_DTD_ELEM_TEXT:
3266 count = xmlOutputBufferWriteString(writer->out, ">");
3275 if (writer->indent) {
3276 count = xmlOutputBufferWriteString(writer->out, "\n");
3282 xmlListPopFront(writer->nodes);
3287 * xmlTextWriterWriteFormatDTDElement:
3288 * @writer: the xmlTextWriterPtr
3289 * @name: the name of the DTD element
3290 * @format: format string (see printf)
3291 * @...: extra parameters for the format
3293 * Write a formatted DTD element.
3295 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3298 xmlTextWriterWriteFormatDTDElement(xmlTextWriterPtr writer,
3299 const xmlChar * name,
3300 const char *format, ...)
3305 va_start(ap, format);
3307 rc = xmlTextWriterWriteVFormatDTDElement(writer, name, format, ap);
3314 * xmlTextWriterWriteVFormatDTDElement:
3315 * @writer: the xmlTextWriterPtr
3316 * @name: the name of the DTD element
3317 * @format: format string (see printf)
3318 * @argptr: pointer to the first member of the variable argument list.
3320 * Write a formatted DTD element.
3322 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3325 xmlTextWriterWriteVFormatDTDElement(xmlTextWriterPtr writer,
3326 const xmlChar * name,
3327 const char *format, va_list argptr)
3335 buf = xmlTextWriterVSprintf(format, argptr);
3339 rc = xmlTextWriterWriteDTDElement(writer, name, buf);
3346 * xmlTextWriterWriteDTDElement:
3347 * @writer: the xmlTextWriterPtr
3348 * @name: the name of the DTD element
3349 * @content: content of the element
3351 * Write a DTD element.
3353 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3356 xmlTextWriterWriteDTDElement(xmlTextWriterPtr writer,
3357 const xmlChar * name, const xmlChar * content)
3362 if (content == NULL)
3366 count = xmlTextWriterStartDTDElement(writer, name);
3371 count = xmlTextWriterWriteString(writer, content);
3376 count = xmlTextWriterEndDTDElement(writer);
3385 * xmlTextWriterStartDTDAttlist:
3386 * @writer: the xmlTextWriterPtr
3387 * @name: the name of the DTD ATTLIST
3389 * Start an xml DTD ATTLIST.
3391 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3394 xmlTextWriterStartDTDAttlist(xmlTextWriterPtr writer, const xmlChar * name)
3399 xmlTextWriterStackEntry *p;
3401 if (writer == NULL || name == NULL || *name == '\0')
3405 lk = xmlListFront(writer->nodes);
3410 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3413 case XML_TEXTWRITER_DTD:
3414 count = xmlOutputBufferWriteString(writer->out, " [");
3418 if (writer->indent) {
3419 count = xmlOutputBufferWriteString(writer->out, "\n");
3424 p->state = XML_TEXTWRITER_DTD_TEXT;
3426 case XML_TEXTWRITER_DTD_TEXT:
3427 case XML_TEXTWRITER_NONE:
3434 p = (xmlTextWriterStackEntry *)
3435 xmlMalloc(sizeof(xmlTextWriterStackEntry));
3437 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
3438 "xmlTextWriterStartDTDAttlist : out of memory!\n");
3442 p->name = xmlStrdup(name);
3444 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
3445 "xmlTextWriterStartDTDAttlist : out of memory!\n");
3449 p->state = XML_TEXTWRITER_DTD_ATTL;
3451 xmlListPushFront(writer->nodes, p);
3453 if (writer->indent) {
3454 count = xmlTextWriterWriteIndent(writer);
3460 count = xmlOutputBufferWriteString(writer->out, "<!ATTLIST ");
3464 count = xmlOutputBufferWriteString(writer->out, (const char *) name);
3473 * xmlTextWriterEndDTDAttlist:
3474 * @writer: the xmlTextWriterPtr
3476 * End an xml DTD attribute list.
3478 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3481 xmlTextWriterEndDTDAttlist(xmlTextWriterPtr writer)
3486 xmlTextWriterStackEntry *p;
3492 lk = xmlListFront(writer->nodes);
3496 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3501 case XML_TEXTWRITER_DTD_ATTL:
3502 case XML_TEXTWRITER_DTD_ATTL_TEXT:
3503 count = xmlOutputBufferWriteString(writer->out, ">");
3512 if (writer->indent) {
3513 count = xmlOutputBufferWriteString(writer->out, "\n");
3519 xmlListPopFront(writer->nodes);
3524 * xmlTextWriterWriteFormatDTDAttlist:
3525 * @writer: the xmlTextWriterPtr
3526 * @name: the name of the DTD ATTLIST
3527 * @format: format string (see printf)
3528 * @...: extra parameters for the format
3530 * Write a formatted DTD ATTLIST.
3532 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3535 xmlTextWriterWriteFormatDTDAttlist(xmlTextWriterPtr writer,
3536 const xmlChar * name,
3537 const char *format, ...)
3542 va_start(ap, format);
3544 rc = xmlTextWriterWriteVFormatDTDAttlist(writer, name, format, ap);
3551 * xmlTextWriterWriteVFormatDTDAttlist:
3552 * @writer: the xmlTextWriterPtr
3553 * @name: the name of the DTD ATTLIST
3554 * @format: format string (see printf)
3555 * @argptr: pointer to the first member of the variable argument list.
3557 * Write a formatted DTD ATTLIST.
3559 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3562 xmlTextWriterWriteVFormatDTDAttlist(xmlTextWriterPtr writer,
3563 const xmlChar * name,
3564 const char *format, va_list argptr)
3572 buf = xmlTextWriterVSprintf(format, argptr);
3576 rc = xmlTextWriterWriteDTDAttlist(writer, name, buf);
3583 * xmlTextWriterWriteDTDAttlist:
3584 * @writer: the xmlTextWriterPtr
3585 * @name: the name of the DTD ATTLIST
3586 * @content: content of the ATTLIST
3588 * Write a DTD ATTLIST.
3590 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3593 xmlTextWriterWriteDTDAttlist(xmlTextWriterPtr writer,
3594 const xmlChar * name, const xmlChar * content)
3599 if (content == NULL)
3603 count = xmlTextWriterStartDTDAttlist(writer, name);
3608 count = xmlTextWriterWriteString(writer, content);
3613 count = xmlTextWriterEndDTDAttlist(writer);
3622 * xmlTextWriterStartDTDEntity:
3623 * @writer: the xmlTextWriterPtr
3624 * @pe: TRUE if this is a parameter entity, FALSE if not
3625 * @name: the name of the DTD ATTLIST
3627 * Start an xml DTD ATTLIST.
3629 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3632 xmlTextWriterStartDTDEntity(xmlTextWriterPtr writer,
3633 int pe, const xmlChar * name)
3638 xmlTextWriterStackEntry *p;
3640 if (writer == NULL || name == NULL || *name == '\0')
3644 lk = xmlListFront(writer->nodes);
3647 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3650 case XML_TEXTWRITER_DTD:
3651 count = xmlOutputBufferWriteString(writer->out, " [");
3655 if (writer->indent) {
3657 xmlOutputBufferWriteString(writer->out, "\n");
3662 p->state = XML_TEXTWRITER_DTD_TEXT;
3664 case XML_TEXTWRITER_DTD_TEXT:
3665 case XML_TEXTWRITER_NONE:
3673 p = (xmlTextWriterStackEntry *)
3674 xmlMalloc(sizeof(xmlTextWriterStackEntry));
3676 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
3677 "xmlTextWriterStartDTDElement : out of memory!\n");
3681 p->name = xmlStrdup(name);
3683 xmlWriterErrMsg(writer, XML_ERR_NO_MEMORY,
3684 "xmlTextWriterStartDTDElement : out of memory!\n");
3690 p->state = XML_TEXTWRITER_DTD_PENT;
3692 p->state = XML_TEXTWRITER_DTD_ENTY;
3694 xmlListPushFront(writer->nodes, p);
3696 if (writer->indent) {
3697 count = xmlTextWriterWriteIndent(writer);
3703 count = xmlOutputBufferWriteString(writer->out, "<!ENTITY ");
3709 count = xmlOutputBufferWriteString(writer->out, "% ");
3715 count = xmlOutputBufferWriteString(writer->out, (const char *) name);
3724 * xmlTextWriterEndDTDEntity:
3725 * @writer: the xmlTextWriterPtr
3727 * End an xml DTD entity.
3729 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3732 xmlTextWriterEndDTDEntity(xmlTextWriterPtr writer)
3737 xmlTextWriterStackEntry *p;
3743 lk = xmlListFront(writer->nodes);
3747 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
3752 case XML_TEXTWRITER_DTD_ENTY_TEXT:
3753 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
3757 case XML_TEXTWRITER_DTD_ENTY:
3758 case XML_TEXTWRITER_DTD_PENT:
3759 count = xmlOutputBufferWriteString(writer->out, ">");
3768 if (writer->indent) {
3769 count = xmlOutputBufferWriteString(writer->out, "\n");
3775 xmlListPopFront(writer->nodes);
3780 * xmlTextWriterWriteFormatDTDInternalEntity:
3781 * @writer: the xmlTextWriterPtr
3782 * @pe: TRUE if this is a parameter entity, FALSE if not
3783 * @name: the name of the DTD entity
3784 * @format: format string (see printf)
3785 * @...: extra parameters for the format
3787 * Write a formatted DTD internal entity.
3789 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3792 xmlTextWriterWriteFormatDTDInternalEntity(xmlTextWriterPtr writer,
3794 const xmlChar * name,
3795 const char *format, ...)
3800 va_start(ap, format);
3802 rc = xmlTextWriterWriteVFormatDTDInternalEntity(writer, pe, name,
3810 * xmlTextWriterWriteVFormatDTDInternalEntity:
3811 * @writer: the xmlTextWriterPtr
3812 * @pe: TRUE if this is a parameter entity, FALSE if not
3813 * @name: the name of the DTD entity
3814 * @format: format string (see printf)
3815 * @argptr: pointer to the first member of the variable argument list.
3817 * Write a formatted DTD internal entity.
3819 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3822 xmlTextWriterWriteVFormatDTDInternalEntity(xmlTextWriterPtr writer,
3824 const xmlChar * name,
3834 buf = xmlTextWriterVSprintf(format, argptr);
3838 rc = xmlTextWriterWriteDTDInternalEntity(writer, pe, name, buf);
3845 * xmlTextWriterWriteDTDEntity:
3846 * @writer: the xmlTextWriterPtr
3847 * @pe: TRUE if this is a parameter entity, FALSE if not
3848 * @name: the name of the DTD entity
3849 * @pubid: the public identifier, which is an alternative to the system identifier
3850 * @sysid: the system identifier, which is the URI of the DTD
3851 * @ndataid: the xml notation name.
3852 * @content: content of the entity
3854 * Write a DTD entity.
3856 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3859 xmlTextWriterWriteDTDEntity(xmlTextWriterPtr writer,
3861 const xmlChar * name,
3862 const xmlChar * pubid,
3863 const xmlChar * sysid,
3864 const xmlChar * ndataid,
3865 const xmlChar * content)
3867 if ((content == NULL) && (pubid == NULL) && (sysid == NULL))
3869 if ((pe != 0) && (ndataid != NULL))
3872 if ((pubid == NULL) && (sysid == NULL))
3873 return xmlTextWriterWriteDTDInternalEntity(writer, pe, name,
3876 return xmlTextWriterWriteDTDExternalEntity(writer, pe, name, pubid,
3881 * xmlTextWriterWriteDTDInternalEntity:
3882 * @writer: the xmlTextWriterPtr
3883 * @pe: TRUE if this is a parameter entity, FALSE if not
3884 * @name: the name of the DTD entity
3885 * @content: content of the entity
3887 * Write a DTD internal entity.
3889 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3892 xmlTextWriterWriteDTDInternalEntity(xmlTextWriterPtr writer,
3894 const xmlChar * name,
3895 const xmlChar * content)
3900 if ((name == NULL) || (*name == '\0') || (content == NULL))
3904 count = xmlTextWriterStartDTDEntity(writer, pe, name);
3909 count = xmlTextWriterWriteString(writer, content);
3914 count = xmlTextWriterEndDTDEntity(writer);
3923 * xmlTextWriterWriteDTDExternalEntity:
3924 * @writer: the xmlTextWriterPtr
3925 * @pe: TRUE if this is a parameter entity, FALSE if not
3926 * @name: the name of the DTD entity
3927 * @pubid: the public identifier, which is an alternative to the system identifier
3928 * @sysid: the system identifier, which is the URI of the DTD
3929 * @ndataid: the xml notation name.
3931 * Write a DTD external entity. The entity must have been started with xmlTextWriterStartDTDEntity
3933 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3936 xmlTextWriterWriteDTDExternalEntity(xmlTextWriterPtr writer,
3938 const xmlChar * name,
3939 const xmlChar * pubid,
3940 const xmlChar * sysid,
3941 const xmlChar * ndataid)
3946 if (((pubid == NULL) && (sysid == NULL)))
3948 if ((pe != 0) && (ndataid != NULL))
3952 count = xmlTextWriterStartDTDEntity(writer, pe, name);
3958 xmlTextWriterWriteDTDExternalEntityContents(writer, pubid, sysid,
3964 count = xmlTextWriterEndDTDEntity(writer);
3973 * xmlTextWriterWriteDTDExternalEntityContents:
3974 * @writer: the xmlTextWriterPtr
3975 * @pubid: the public identifier, which is an alternative to the system identifier
3976 * @sysid: the system identifier, which is the URI of the DTD
3977 * @ndataid: the xml notation name.
3979 * Write the contents of a DTD external entity.
3981 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3984 xmlTextWriterWriteDTDExternalEntityContents(xmlTextWriterPtr writer,
3985 const xmlChar * pubid,
3986 const xmlChar * sysid,
3987 const xmlChar * ndataid)
3992 xmlTextWriterStackEntry *p;
3994 if (writer == NULL) {
3995 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
3996 "xmlTextWriterWriteDTDExternalEntityContents: xmlTextWriterPtr invalid!\n");
4001 lk = xmlListFront(writer->nodes);
4003 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
4004 "xmlTextWriterWriteDTDExternalEntityContents: you must call xmlTextWriterStartDTDEntity before the call to this function!\n");
4008 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
4013 case XML_TEXTWRITER_DTD_ENTY:
4015 case XML_TEXTWRITER_DTD_PENT:
4016 if (ndataid != NULL) {
4017 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
4018 "xmlTextWriterWriteDTDExternalEntityContents: notation not allowed with parameter entities!\n");
4023 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
4024 "xmlTextWriterWriteDTDExternalEntityContents: you must call xmlTextWriterStartDTDEntity before the call to this function!\n");
4030 xmlWriterErrMsg(writer, XML_ERR_INTERNAL_ERROR,
4031 "xmlTextWriterWriteDTDExternalEntityContents: system identifier needed!\n");
4035 count = xmlOutputBufferWriteString(writer->out, " PUBLIC ");
4040 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
4046 xmlOutputBufferWriteString(writer->out, (const char *) pubid);
4051 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
4059 count = xmlOutputBufferWriteString(writer->out, " SYSTEM");
4065 count = xmlOutputBufferWriteString(writer->out, " ");
4070 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
4076 xmlOutputBufferWriteString(writer->out, (const char *) sysid);
4081 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
4087 if (ndataid != NULL) {
4088 count = xmlOutputBufferWriteString(writer->out, " NDATA ");
4094 xmlOutputBufferWriteString(writer->out,
4095 (const char *) ndataid);
4105 * xmlTextWriterWriteDTDNotation:
4106 * @writer: the xmlTextWriterPtr
4107 * @name: the name of the xml notation
4108 * @pubid: the public identifier, which is an alternative to the system identifier
4109 * @sysid: the system identifier, which is the URI of the DTD
4111 * Write a DTD entity.
4113 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
4116 xmlTextWriterWriteDTDNotation(xmlTextWriterPtr writer,
4117 const xmlChar * name,
4118 const xmlChar * pubid, const xmlChar * sysid)
4123 xmlTextWriterStackEntry *p;
4125 if (writer == NULL || name == NULL || *name == '\0')
4129 lk = xmlListFront(writer->nodes);
4134 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
4137 case XML_TEXTWRITER_DTD:
4138 count = xmlOutputBufferWriteString(writer->out, " [");
4142 if (writer->indent) {
4143 count = xmlOutputBufferWriteString(writer->out, "\n");
4148 p->state = XML_TEXTWRITER_DTD_TEXT;
4150 case XML_TEXTWRITER_DTD_TEXT:
4157 if (writer->indent) {
4158 count = xmlTextWriterWriteIndent(writer);
4164 count = xmlOutputBufferWriteString(writer->out, "<!NOTATION ");
4168 count = xmlOutputBufferWriteString(writer->out, (const char *) name);
4174 count = xmlOutputBufferWriteString(writer->out, " PUBLIC ");
4178 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
4183 xmlOutputBufferWriteString(writer->out, (const char *) pubid);
4187 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
4195 count = xmlOutputBufferWriteString(writer->out, " SYSTEM");
4200 count = xmlOutputBufferWriteString(writer->out, " ");
4204 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
4209 xmlOutputBufferWriteString(writer->out, (const char *) sysid);
4213 count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar);
4219 count = xmlOutputBufferWriteString(writer->out, ">");
4228 * xmlTextWriterFlush:
4229 * @writer: the xmlTextWriterPtr
4231 * Flush the output buffer.
4233 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
4236 xmlTextWriterFlush(xmlTextWriterPtr writer)
4243 if (writer->out == NULL)
4246 count = xmlOutputBufferFlush(writer->out);
4256 * xmlFreeTextWriterStackEntry:
4257 * @lk: the xmlLinkPtr
4259 * Free callback for the xmlList.
4262 xmlFreeTextWriterStackEntry(xmlLinkPtr lk)
4264 xmlTextWriterStackEntry *p;
4266 p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk);
4276 * xmlCmpTextWriterStackEntry:
4277 * @data0: the first data
4278 * @data1: the second data
4280 * Compare callback for the xmlList.
4285 xmlCmpTextWriterStackEntry(const void *data0, const void *data1)
4287 xmlTextWriterStackEntry *p0;
4288 xmlTextWriterStackEntry *p1;
4299 p0 = (xmlTextWriterStackEntry *) data0;
4300 p1 = (xmlTextWriterStackEntry *) data1;
4302 return xmlStrcmp(p0->name, p1->name);
4310 * xmlTextWriterOutputNSDecl:
4311 * @writer: the xmlTextWriterPtr
4313 * Output the current namespace declarations.
4316 xmlTextWriterOutputNSDecl(xmlTextWriterPtr writer)
4319 xmlTextWriterNsStackEntry *np;
4324 while (!xmlListEmpty(writer->nsstack)) {
4325 xmlChar *namespaceURI = NULL;
4326 xmlChar *prefix = NULL;
4328 lk = xmlListFront(writer->nsstack);
4329 np = (xmlTextWriterNsStackEntry *) xmlLinkGetData(lk);
4332 namespaceURI = xmlStrdup(np->uri);
4333 prefix = xmlStrdup(np->prefix);
4336 xmlListPopFront(writer->nsstack);
4339 count = xmlTextWriterWriteAttribute(writer, prefix, namespaceURI);
4340 xmlFree(namespaceURI);
4344 xmlListDelete(writer->nsstack);
4345 writer->nsstack = NULL;
4355 * xmlFreeTextWriterNsStackEntry:
4356 * @lk: the xmlLinkPtr
4358 * Free callback for the xmlList.
4361 xmlFreeTextWriterNsStackEntry(xmlLinkPtr lk)
4363 xmlTextWriterNsStackEntry *p;
4365 p = (xmlTextWriterNsStackEntry *) xmlLinkGetData(lk);
4378 * xmlCmpTextWriterNsStackEntry:
4379 * @data0: the first data
4380 * @data1: the second data
4382 * Compare callback for the xmlList.
4387 xmlCmpTextWriterNsStackEntry(const void *data0, const void *data1)
4389 xmlTextWriterNsStackEntry *p0;
4390 xmlTextWriterNsStackEntry *p1;
4402 p0 = (xmlTextWriterNsStackEntry *) data0;
4403 p1 = (xmlTextWriterNsStackEntry *) data1;
4405 rc = xmlStrcmp(p0->prefix, p1->prefix);
4407 if ((rc != 0) || (p0->elem != p1->elem))
4414 * xmlTextWriterWriteDocCallback:
4415 * @context: the xmlBufferPtr
4416 * @str: the data to write
4417 * @len: the length of the data
4419 * Write callback for the xmlOutputBuffer with target xmlBuffer
4424 xmlTextWriterWriteDocCallback(void *context, const xmlChar * str, int len)
4426 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) context;
4429 if ((rc = xmlParseChunk(ctxt, (const char *) str, len, 0)) != 0) {
4430 xmlWriterErrMsgInt(NULL, XML_ERR_INTERNAL_ERROR,
4431 "xmlTextWriterWriteDocCallback : XML error %d !\n",
4440 * xmlTextWriterCloseDocCallback:
4441 * @context: the xmlBufferPtr
4443 * Close callback for the xmlOutputBuffer with target xmlBuffer
4448 xmlTextWriterCloseDocCallback(void *context)
4450 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) context;
4453 if ((rc = xmlParseChunk(ctxt, NULL, 0, 1)) != 0) {
4454 xmlWriterErrMsgInt(NULL, XML_ERR_INTERNAL_ERROR,
4455 "xmlTextWriterWriteDocCallback : XML error %d !\n",
4464 * xmlTextWriterVSprintf:
4465 * @format: see printf
4466 * @argptr: pointer to the first member of the variable argument list.
4468 * Utility function for formatted output
4470 * Returns a new xmlChar buffer with the data or NULL on error. This buffer must be freed.
4473 xmlTextWriterVSprintf(const char *format, va_list argptr)
4481 buf = (xmlChar *) xmlMalloc(size);
4483 xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
4484 "xmlTextWriterVSprintf : out of memory!\n");
4488 VA_COPY(locarg, argptr);
4489 while (((count = vsnprintf((char *) buf, size, format, locarg)) < 0)
4490 || (count == size - 1) || (count == size) || (count > size)) {
4494 buf = (xmlChar *) xmlMalloc(size);
4496 xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
4497 "xmlTextWriterVSprintf : out of memory!\n");
4500 VA_COPY(locarg, argptr);
4508 * xmlTextWriterStartDocumentCallback:
4509 * @ctx: the user data (XML parser context)
4511 * called at the start of document processing.
4514 xmlTextWriterStartDocumentCallback(void *ctx)
4516 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
4520 #ifdef LIBXML_HTML_ENABLED
4521 if (ctxt->myDoc == NULL)
4522 ctxt->myDoc = htmlNewDocNoDtD(NULL, NULL);
4523 if (ctxt->myDoc == NULL) {
4524 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4525 ctxt->sax->error(ctxt->userData,
4526 "SAX.startDocument(): out of memory\n");
4527 ctxt->errNo = XML_ERR_NO_MEMORY;
4528 ctxt->instate = XML_PARSER_EOF;
4529 ctxt->disableSAX = 1;
4533 xmlWriterErrMsg(NULL, XML_ERR_INTERNAL_ERROR,
4534 "libxml2 built without HTML support\n");
4535 ctxt->errNo = XML_ERR_INTERNAL_ERROR;
4536 ctxt->instate = XML_PARSER_EOF;
4537 ctxt->disableSAX = 1;
4543 doc = ctxt->myDoc = xmlNewDoc(ctxt->version);
4545 if (doc->children == NULL) {
4546 if (ctxt->encoding != NULL)
4547 doc->encoding = xmlStrdup(ctxt->encoding);
4549 doc->encoding = NULL;
4550 doc->standalone = ctxt->standalone;
4553 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4554 ctxt->sax->error(ctxt->userData,
4555 "SAX.startDocument(): out of memory\n");
4556 ctxt->errNo = XML_ERR_NO_MEMORY;
4557 ctxt->instate = XML_PARSER_EOF;
4558 ctxt->disableSAX = 1;
4562 if ((ctxt->myDoc != NULL) && (ctxt->myDoc->URL == NULL) &&
4563 (ctxt->input != NULL) && (ctxt->input->filename != NULL)) {
4565 xmlCanonicPath((const xmlChar *) ctxt->input->filename);
4566 if (ctxt->myDoc->URL == NULL)
4568 xmlStrdup((const xmlChar *) ctxt->input->filename);
4573 * xmlTextWriterSetIndent:
4574 * @writer: the xmlTextWriterPtr
4575 * @indent: do indentation?
4577 * Set indentation output. indent = 0 do not indentation. indent > 0 do indentation.
4579 * Returns -1 on error or 0 otherwise.
4582 xmlTextWriterSetIndent(xmlTextWriterPtr writer, int indent)
4584 if ((writer == NULL) || (indent < 0))
4587 writer->indent = indent;
4588 writer->doindent = 1;
4594 * xmlTextWriterSetIndentString:
4595 * @writer: the xmlTextWriterPtr
4596 * @str: the xmlChar string
4598 * Set string indentation.
4600 * Returns -1 on error or 0 otherwise.
4603 xmlTextWriterSetIndentString(xmlTextWriterPtr writer, const xmlChar * str)
4605 if ((writer == NULL) || (!str))
4608 if (writer->ichar != NULL)
4609 xmlFree(writer->ichar);
4610 writer->ichar = xmlStrdup(str);
4619 * xmlTextWriterSetQuoteChar:
4620 * @writer: the xmlTextWriterPtr
4621 * @quotechar: the quote character
4623 * Set the character used for quoting attributes.
4625 * Returns -1 on error or 0 otherwise.
4628 xmlTextWriterSetQuoteChar(xmlTextWriterPtr writer, xmlChar quotechar)
4630 if ((writer == NULL) || ((quotechar != '\'') && (quotechar != '"')))
4633 writer->qchar = quotechar;
4639 * xmlTextWriterWriteIndent:
4640 * @writer: the xmlTextWriterPtr
4642 * Write indent string.
4644 * Returns -1 on error or the number of strings written.
4647 xmlTextWriterWriteIndent(xmlTextWriterPtr writer)
4653 lksize = xmlListSize(writer->nodes);
4655 return (-1); /* list is empty */
4656 for (i = 0; i < (lksize - 1); i++) {
4657 ret = xmlOutputBufferWriteString(writer->out,
4658 (const char *) writer->ichar);
4663 return (lksize - 1);
4667 * xmlTextWriterHandleStateDependencies:
4668 * @writer: the xmlTextWriterPtr
4669 * @p: the xmlTextWriterStackEntry
4671 * Write state dependent strings.
4673 * Returns -1 on error or the number of characters written.
4676 xmlTextWriterHandleStateDependencies(xmlTextWriterPtr writer,
4677 xmlTextWriterStackEntry * p)
4690 extra[0] = extra[1] = extra[2] = '\0';
4694 case XML_TEXTWRITER_NAME:
4695 /* Output namespace declarations */
4696 count = xmlTextWriterOutputNSDecl(writer);
4701 p->state = XML_TEXTWRITER_TEXT;
4703 case XML_TEXTWRITER_PI:
4705 p->state = XML_TEXTWRITER_PI_TEXT;
4707 case XML_TEXTWRITER_DTD:
4710 p->state = XML_TEXTWRITER_DTD_TEXT;
4712 case XML_TEXTWRITER_DTD_ELEM:
4714 p->state = XML_TEXTWRITER_DTD_ELEM_TEXT;
4716 case XML_TEXTWRITER_DTD_ATTL:
4718 p->state = XML_TEXTWRITER_DTD_ATTL_TEXT;
4720 case XML_TEXTWRITER_DTD_ENTY:
4721 case XML_TEXTWRITER_DTD_PENT:
4723 extra[1] = writer->qchar;
4724 p->state = XML_TEXTWRITER_DTD_ENTY_TEXT;
4731 if (*extra != '\0') {
4732 count = xmlOutputBufferWriteString(writer->out, extra);
4741 #define bottom_xmlwriter
4742 #include "elfgcchack.h"