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 (i.e. it may need
35 * something involving a memcpy) but (hopefully) will be
36 * sufficient for libxml2.
40 #define VA_COPY(dest, src) va_copy(dest, src)
43 #define VA_COPY(dest,src) __va_copy(dest, src)
45 #define VA_COPY(dest,src) (dest) = (src)
51 * Types are kept private
54 XML_TEXTWRITER_NONE
= 0,
56 XML_TEXTWRITER_ATTRIBUTE
,
59 XML_TEXTWRITER_PI_TEXT
,
62 XML_TEXTWRITER_DTD_TEXT
,
63 XML_TEXTWRITER_DTD_ELEM
,
64 XML_TEXTWRITER_DTD_ELEM_TEXT
,
65 XML_TEXTWRITER_DTD_ATTL
,
66 XML_TEXTWRITER_DTD_ATTL_TEXT
,
67 XML_TEXTWRITER_DTD_ENTY
, /* entity */
68 XML_TEXTWRITER_DTD_ENTY_TEXT
,
69 XML_TEXTWRITER_DTD_PENT
, /* parameter entity */
70 XML_TEXTWRITER_COMMENT
73 typedef struct _xmlTextWriterStackEntry xmlTextWriterStackEntry
;
75 struct _xmlTextWriterStackEntry
{
77 xmlTextWriterState state
;
80 typedef struct _xmlTextWriterNsStackEntry xmlTextWriterNsStackEntry
;
81 struct _xmlTextWriterNsStackEntry
{
87 struct _xmlTextWriter
{
88 xmlOutputBufferPtr out
; /* output buffer */
89 xmlListPtr nodes
; /* element name stack */
90 xmlListPtr nsstack
; /* name spaces stack */
92 int indent
; /* enable indent */
93 int doindent
; /* internal indent flag */
94 xmlChar
*ichar
; /* indent character */
95 char qchar
; /* character used for quoting attribute values */
96 xmlParserCtxtPtr ctxt
;
101 static void xmlFreeTextWriterStackEntry(xmlLinkPtr lk
);
102 static int xmlCmpTextWriterStackEntry(const void *data0
,
104 static int xmlTextWriterOutputNSDecl(xmlTextWriterPtr writer
);
105 static void xmlFreeTextWriterNsStackEntry(xmlLinkPtr lk
);
106 static int xmlCmpTextWriterNsStackEntry(const void *data0
,
108 static int xmlTextWriterWriteDocCallback(void *context
,
109 const xmlChar
* str
, int len
);
110 static int xmlTextWriterCloseDocCallback(void *context
);
112 static xmlChar
*xmlTextWriterVSprintf(const char *format
, va_list argptr
);
113 static int xmlOutputBufferWriteBase64(xmlOutputBufferPtr out
, int len
,
114 const unsigned char *data
);
115 static void xmlTextWriterStartDocumentCallback(void *ctx
);
116 static int xmlTextWriterWriteIndent(xmlTextWriterPtr writer
);
118 xmlTextWriterHandleStateDependencies(xmlTextWriterPtr writer
,
119 xmlTextWriterStackEntry
* p
);
123 * @ctxt: a writer context
124 * @error: the error number
125 * @msg: the error message
127 * Handle a writer error
130 xmlWriterErrMsg(xmlTextWriterPtr ctxt
, xmlParserErrors error
,
134 __xmlRaiseError(NULL
, NULL
, NULL
, ctxt
->ctxt
,
135 NULL
, XML_FROM_WRITER
, error
, XML_ERR_FATAL
,
136 NULL
, 0, NULL
, NULL
, NULL
, 0, 0, "%s", msg
);
138 __xmlRaiseError(NULL
, NULL
, NULL
, NULL
, NULL
, XML_FROM_WRITER
, error
,
139 XML_ERR_FATAL
, NULL
, 0, NULL
, NULL
, NULL
, 0, 0, "%s", msg
);
144 * xmlWriterErrMsgInt:
145 * @ctxt: a writer context
146 * @error: the error number
147 * @msg: the error message
150 * Handle a writer error
153 xmlWriterErrMsgInt(xmlTextWriterPtr ctxt
, xmlParserErrors error
,
154 const char *msg
, int val
)
157 __xmlRaiseError(NULL
, NULL
, NULL
, ctxt
->ctxt
,
158 NULL
, XML_FROM_WRITER
, error
, XML_ERR_FATAL
,
159 NULL
, 0, NULL
, NULL
, NULL
, val
, 0, msg
, val
);
161 __xmlRaiseError(NULL
, NULL
, NULL
, NULL
, NULL
, XML_FROM_WRITER
, error
,
162 XML_ERR_FATAL
, NULL
, 0, NULL
, NULL
, NULL
, val
, 0, msg
, val
);
168 * @out: an xmlOutputBufferPtr
170 * Create a new xmlNewTextWriter structure using an xmlOutputBufferPtr
171 * NOTE: the @out parameter will be deallocated when the writer is closed
172 * (if the call succeed.)
174 * Returns the new xmlTextWriterPtr or NULL in case of error
177 xmlNewTextWriter(xmlOutputBufferPtr out
)
179 xmlTextWriterPtr ret
;
181 ret
= (xmlTextWriterPtr
) xmlMalloc(sizeof(xmlTextWriter
));
183 xmlWriterErrMsg(NULL
, XML_ERR_NO_MEMORY
,
184 "xmlNewTextWriter : out of memory!\n");
187 memset(ret
, 0, (size_t) sizeof(xmlTextWriter
));
189 ret
->nodes
= xmlListCreate((xmlListDeallocator
)
190 xmlFreeTextWriterStackEntry
,
192 xmlCmpTextWriterStackEntry
);
193 if (ret
->nodes
== NULL
) {
194 xmlWriterErrMsg(NULL
, XML_ERR_NO_MEMORY
,
195 "xmlNewTextWriter : out of memory!\n");
200 ret
->nsstack
= xmlListCreate((xmlListDeallocator
)
201 xmlFreeTextWriterNsStackEntry
,
203 xmlCmpTextWriterNsStackEntry
);
204 if (ret
->nsstack
== NULL
) {
205 xmlWriterErrMsg(NULL
, XML_ERR_NO_MEMORY
,
206 "xmlNewTextWriter : out of memory!\n");
207 xmlListDelete(ret
->nodes
);
213 ret
->ichar
= xmlStrdup(BAD_CAST
" ");
217 xmlListDelete(ret
->nodes
);
218 xmlListDelete(ret
->nsstack
);
220 xmlWriterErrMsg(NULL
, XML_ERR_NO_MEMORY
,
221 "xmlNewTextWriter : out of memory!\n");
225 ret
->doc
= xmlNewDoc(NULL
);
227 ret
->no_doc_free
= 0;
233 * xmlNewTextWriterFilename:
234 * @uri: the URI of the resource for the output
235 * @compression: compress the output?
237 * Create a new xmlNewTextWriter structure with @uri as output
239 * Returns the new xmlTextWriterPtr or NULL in case of error
242 xmlNewTextWriterFilename(const char *uri
, int compression
)
244 xmlTextWriterPtr ret
;
245 xmlOutputBufferPtr out
;
247 out
= xmlOutputBufferCreateFilename(uri
, NULL
, compression
);
249 xmlWriterErrMsg(NULL
, XML_IO_EIO
,
250 "xmlNewTextWriterFilename : cannot open uri\n");
254 ret
= xmlNewTextWriter(out
);
256 xmlWriterErrMsg(NULL
, XML_ERR_NO_MEMORY
,
257 "xmlNewTextWriterFilename : out of memory!\n");
258 xmlOutputBufferClose(out
);
268 * xmlNewTextWriterMemory:
270 * @compression: compress the output?
272 * Create a new xmlNewTextWriter structure with @buf as output
273 * TODO: handle compression
275 * Returns the new xmlTextWriterPtr or NULL in case of error
278 xmlNewTextWriterMemory(xmlBufferPtr buf
, int compression ATTRIBUTE_UNUSED
)
280 xmlTextWriterPtr ret
;
281 xmlOutputBufferPtr out
;
283 /*::todo handle compression */
284 out
= xmlOutputBufferCreateBuffer(buf
, NULL
);
287 xmlWriterErrMsg(NULL
, XML_ERR_NO_MEMORY
,
288 "xmlNewTextWriterMemory : out of memory!\n");
292 ret
= xmlNewTextWriter(out
);
294 xmlWriterErrMsg(NULL
, XML_ERR_NO_MEMORY
,
295 "xmlNewTextWriterMemory : out of memory!\n");
296 xmlOutputBufferClose(out
);
304 * xmlNewTextWriterPushParser:
305 * @ctxt: xmlParserCtxtPtr to hold the new XML document tree
306 * @compression: compress the output?
308 * Create a new xmlNewTextWriter structure with @ctxt as output
309 * NOTE: the @ctxt context will be freed with the resulting writer
310 * (if the call succeeds).
311 * TODO: handle compression
313 * Returns the new xmlTextWriterPtr or NULL in case of error
316 xmlNewTextWriterPushParser(xmlParserCtxtPtr ctxt
,
317 int compression ATTRIBUTE_UNUSED
)
319 xmlTextWriterPtr ret
;
320 xmlOutputBufferPtr out
;
323 xmlWriterErrMsg(NULL
, XML_ERR_INTERNAL_ERROR
,
324 "xmlNewTextWriterPushParser : invalid context!\n");
328 out
= xmlOutputBufferCreateIO((xmlOutputWriteCallback
)
329 xmlTextWriterWriteDocCallback
,
330 (xmlOutputCloseCallback
)
331 xmlTextWriterCloseDocCallback
,
332 (void *) ctxt
, NULL
);
334 xmlWriterErrMsg(NULL
, XML_ERR_INTERNAL_ERROR
,
335 "xmlNewTextWriterPushParser : error at xmlOutputBufferCreateIO!\n");
339 ret
= xmlNewTextWriter(out
);
341 xmlWriterErrMsg(NULL
, XML_ERR_INTERNAL_ERROR
,
342 "xmlNewTextWriterPushParser : error at xmlNewTextWriter!\n");
343 xmlOutputBufferClose(out
);
353 * xmlNewTextWriterDoc:
354 * @doc: address of a xmlDocPtr to hold the new XML document tree
355 * @compression: compress the output?
357 * Create a new xmlNewTextWriter structure with @*doc as output
359 * Returns the new xmlTextWriterPtr or NULL in case of error
362 xmlNewTextWriterDoc(xmlDocPtr
* doc
, int compression
)
364 xmlTextWriterPtr ret
;
365 xmlSAXHandler saxHandler
;
366 xmlParserCtxtPtr ctxt
;
368 memset(&saxHandler
, '\0', sizeof(saxHandler
));
369 xmlSAX2InitDefaultSAXHandler(&saxHandler
, 1);
370 saxHandler
.startDocument
= xmlTextWriterStartDocumentCallback
;
371 saxHandler
.startElement
= xmlSAX2StartElement
;
372 saxHandler
.endElement
= xmlSAX2EndElement
;
374 ctxt
= xmlCreatePushParserCtxt(&saxHandler
, NULL
, NULL
, 0, NULL
);
376 xmlWriterErrMsg(NULL
, XML_ERR_INTERNAL_ERROR
,
377 "xmlNewTextWriterDoc : error at xmlCreatePushParserCtxt!\n");
381 * For some reason this seems to completely break if node names
386 ctxt
->myDoc
= xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION
);
387 if (ctxt
->myDoc
== NULL
) {
388 xmlFreeParserCtxt(ctxt
);
389 xmlWriterErrMsg(NULL
, XML_ERR_INTERNAL_ERROR
,
390 "xmlNewTextWriterDoc : error at xmlNewDoc!\n");
394 ret
= xmlNewTextWriterPushParser(ctxt
, compression
);
396 xmlFreeDoc(ctxt
->myDoc
);
397 xmlFreeParserCtxt(ctxt
);
398 xmlWriterErrMsg(NULL
, XML_ERR_INTERNAL_ERROR
,
399 "xmlNewTextWriterDoc : error at xmlNewTextWriterPushParser!\n");
403 xmlSetDocCompressMode(ctxt
->myDoc
, compression
);
407 ret
->no_doc_free
= 1;
414 * xmlNewTextWriterTree:
416 * @node: xmlNodePtr or NULL for doc->children
417 * @compression: compress the output?
419 * Create a new xmlNewTextWriter structure with @doc as output
422 * Returns the new xmlTextWriterPtr or NULL in case of error
425 xmlNewTextWriterTree(xmlDocPtr doc
, xmlNodePtr node
, int compression
)
427 xmlTextWriterPtr ret
;
428 xmlSAXHandler saxHandler
;
429 xmlParserCtxtPtr ctxt
;
432 xmlWriterErrMsg(NULL
, XML_ERR_INTERNAL_ERROR
,
433 "xmlNewTextWriterTree : invalid document tree!\n");
437 memset(&saxHandler
, '\0', sizeof(saxHandler
));
438 xmlSAX2InitDefaultSAXHandler(&saxHandler
, 1);
439 saxHandler
.startDocument
= xmlTextWriterStartDocumentCallback
;
440 saxHandler
.startElement
= xmlSAX2StartElement
;
441 saxHandler
.endElement
= xmlSAX2EndElement
;
443 ctxt
= xmlCreatePushParserCtxt(&saxHandler
, NULL
, NULL
, 0, NULL
);
445 xmlWriterErrMsg(NULL
, XML_ERR_INTERNAL_ERROR
,
446 "xmlNewTextWriterDoc : error at xmlCreatePushParserCtxt!\n");
450 * For some reason this seems to completely break if node names
455 ret
= xmlNewTextWriterPushParser(ctxt
, compression
);
457 xmlFreeParserCtxt(ctxt
);
458 xmlWriterErrMsg(NULL
, XML_ERR_INTERNAL_ERROR
,
459 "xmlNewTextWriterDoc : error at xmlNewTextWriterPushParser!\n");
465 ret
->no_doc_free
= 1;
467 xmlSetDocCompressMode(doc
, compression
);
474 * @writer: the xmlTextWriterPtr
476 * Deallocate all the resources associated to the writer
479 xmlFreeTextWriter(xmlTextWriterPtr writer
)
484 if (writer
->out
!= NULL
)
485 xmlOutputBufferClose(writer
->out
);
487 if (writer
->nodes
!= NULL
)
488 xmlListDelete(writer
->nodes
);
490 if (writer
->nsstack
!= NULL
)
491 xmlListDelete(writer
->nsstack
);
493 if (writer
->ctxt
!= NULL
) {
494 if ((writer
->ctxt
->myDoc
!= NULL
) && (writer
->no_doc_free
== 0)) {
495 xmlFreeDoc(writer
->ctxt
->myDoc
);
496 writer
->ctxt
->myDoc
= NULL
;
498 xmlFreeParserCtxt(writer
->ctxt
);
501 if (writer
->doc
!= NULL
)
502 xmlFreeDoc(writer
->doc
);
504 if (writer
->ichar
!= NULL
)
505 xmlFree(writer
->ichar
);
510 * xmlTextWriterStartDocument:
511 * @writer: the xmlTextWriterPtr
512 * @version: the xml version ("1.0") or NULL for default ("1.0")
513 * @encoding: the encoding or NULL for default
514 * @standalone: "yes" or "no" or NULL for default
516 * Start a new xml document
518 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
521 xmlTextWriterStartDocument(xmlTextWriterPtr writer
, const char *version
,
522 const char *encoding
, const char *standalone
)
527 xmlCharEncodingHandlerPtr encoder
;
529 if ((writer
== NULL
) || (writer
->out
== NULL
)) {
530 xmlWriterErrMsg(writer
, XML_ERR_INTERNAL_ERROR
,
531 "xmlTextWriterStartDocument : invalid writer!\n");
535 lk
= xmlListFront(writer
->nodes
);
536 if ((lk
!= NULL
) && (xmlLinkGetData(lk
) != NULL
)) {
537 xmlWriterErrMsg(writer
, XML_ERR_INTERNAL_ERROR
,
538 "xmlTextWriterStartDocument : not allowed in this context!\n");
543 if (encoding
!= NULL
) {
544 encoder
= xmlFindCharEncodingHandler(encoding
);
545 if (encoder
== NULL
) {
546 xmlWriterErrMsg(writer
, XML_ERR_NO_MEMORY
,
547 "xmlTextWriterStartDocument : out of memory!\n");
552 writer
->out
->encoder
= encoder
;
553 if (encoder
!= NULL
) {
554 if (writer
->out
->conv
== NULL
) {
555 writer
->out
->conv
= xmlBufCreateSize(4000);
557 xmlCharEncOutput(writer
->out
, 1);
558 if ((writer
->doc
!= NULL
) && (writer
->doc
->encoding
== NULL
))
559 writer
->doc
->encoding
= xmlStrdup((xmlChar
*)writer
->out
->encoder
->name
);
561 writer
->out
->conv
= NULL
;
564 count
= xmlOutputBufferWriteString(writer
->out
, "<?xml version=");
568 count
= xmlOutputBufferWrite(writer
->out
, 1, &writer
->qchar
);
573 count
= xmlOutputBufferWriteString(writer
->out
, version
);
575 count
= xmlOutputBufferWriteString(writer
->out
, "1.0");
579 count
= xmlOutputBufferWrite(writer
->out
, 1, &writer
->qchar
);
583 if (writer
->out
->encoder
!= 0) {
584 count
= xmlOutputBufferWriteString(writer
->out
, " encoding=");
588 count
= xmlOutputBufferWrite(writer
->out
, 1, &writer
->qchar
);
593 xmlOutputBufferWriteString(writer
->out
,
594 writer
->out
->encoder
->name
);
598 count
= xmlOutputBufferWrite(writer
->out
, 1, &writer
->qchar
);
604 if (standalone
!= 0) {
605 count
= xmlOutputBufferWriteString(writer
->out
, " standalone=");
609 count
= xmlOutputBufferWrite(writer
->out
, 1, &writer
->qchar
);
613 count
= xmlOutputBufferWriteString(writer
->out
, standalone
);
617 count
= xmlOutputBufferWrite(writer
->out
, 1, &writer
->qchar
);
623 count
= xmlOutputBufferWriteString(writer
->out
, "?>\n");
632 * xmlTextWriterEndDocument:
633 * @writer: the xmlTextWriterPtr
635 * End an xml document. All open elements are closed, and
636 * the content is flushed to the output.
638 * Returns the bytes written or -1 in case of error
641 xmlTextWriterEndDocument(xmlTextWriterPtr writer
)
646 xmlTextWriterStackEntry
*p
;
648 if (writer
== NULL
) {
649 xmlWriterErrMsg(writer
, XML_ERR_INTERNAL_ERROR
,
650 "xmlTextWriterEndDocument : invalid writer!\n");
655 while ((lk
= xmlListFront(writer
->nodes
)) != NULL
) {
656 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
660 case XML_TEXTWRITER_NAME
:
661 case XML_TEXTWRITER_ATTRIBUTE
:
662 case XML_TEXTWRITER_TEXT
:
663 count
= xmlTextWriterEndElement(writer
);
668 case XML_TEXTWRITER_PI
:
669 case XML_TEXTWRITER_PI_TEXT
:
670 count
= xmlTextWriterEndPI(writer
);
675 case XML_TEXTWRITER_CDATA
:
676 count
= xmlTextWriterEndCDATA(writer
);
681 case XML_TEXTWRITER_DTD
:
682 case XML_TEXTWRITER_DTD_TEXT
:
683 case XML_TEXTWRITER_DTD_ELEM
:
684 case XML_TEXTWRITER_DTD_ELEM_TEXT
:
685 case XML_TEXTWRITER_DTD_ATTL
:
686 case XML_TEXTWRITER_DTD_ATTL_TEXT
:
687 case XML_TEXTWRITER_DTD_ENTY
:
688 case XML_TEXTWRITER_DTD_ENTY_TEXT
:
689 case XML_TEXTWRITER_DTD_PENT
:
690 count
= xmlTextWriterEndDTD(writer
);
695 case XML_TEXTWRITER_COMMENT
:
696 count
= xmlTextWriterEndComment(writer
);
706 if (!writer
->indent
) {
707 count
= xmlOutputBufferWriteString(writer
->out
, "\n");
713 sum
+= xmlTextWriterFlush(writer
);
719 * xmlTextWriterStartComment:
720 * @writer: the xmlTextWriterPtr
722 * Start an xml comment.
724 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
727 xmlTextWriterStartComment(xmlTextWriterPtr writer
)
732 xmlTextWriterStackEntry
*p
;
734 if (writer
== NULL
) {
735 xmlWriterErrMsg(writer
, XML_ERR_INTERNAL_ERROR
,
736 "xmlTextWriterStartComment : invalid writer!\n");
741 lk
= xmlListFront(writer
->nodes
);
743 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
746 case XML_TEXTWRITER_TEXT
:
747 case XML_TEXTWRITER_NONE
:
749 case XML_TEXTWRITER_NAME
:
750 /* Output namespace declarations */
751 count
= xmlTextWriterOutputNSDecl(writer
);
755 count
= xmlOutputBufferWriteString(writer
->out
, ">");
759 if (writer
->indent
) {
761 xmlOutputBufferWriteString(writer
->out
, "\n");
766 p
->state
= XML_TEXTWRITER_TEXT
;
774 p
= (xmlTextWriterStackEntry
*)
775 xmlMalloc(sizeof(xmlTextWriterStackEntry
));
777 xmlWriterErrMsg(writer
, XML_ERR_NO_MEMORY
,
778 "xmlTextWriterStartElement : out of memory!\n");
783 p
->state
= XML_TEXTWRITER_COMMENT
;
785 xmlListPushFront(writer
->nodes
, p
);
787 if (writer
->indent
) {
788 count
= xmlTextWriterWriteIndent(writer
);
794 count
= xmlOutputBufferWriteString(writer
->out
, "<!--");
803 * xmlTextWriterEndComment:
804 * @writer: the xmlTextWriterPtr
806 * End the current xml coment.
808 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
811 xmlTextWriterEndComment(xmlTextWriterPtr writer
)
816 xmlTextWriterStackEntry
*p
;
818 if (writer
== NULL
) {
819 xmlWriterErrMsg(writer
, XML_ERR_INTERNAL_ERROR
,
820 "xmlTextWriterEndComment : invalid writer!\n");
824 lk
= xmlListFront(writer
->nodes
);
826 xmlWriterErrMsg(writer
, XML_ERR_INTERNAL_ERROR
,
827 "xmlTextWriterEndComment : not allowed in this context!\n");
831 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
837 case XML_TEXTWRITER_COMMENT
:
838 count
= xmlOutputBufferWriteString(writer
->out
, "-->");
847 if (writer
->indent
) {
848 count
= xmlOutputBufferWriteString(writer
->out
, "\n");
854 xmlListPopFront(writer
->nodes
);
859 * xmlTextWriterWriteFormatComment:
860 * @writer: the xmlTextWriterPtr
861 * @format: format string (see printf)
862 * @...: extra parameters for the format
864 * Write an xml comment.
866 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
869 xmlTextWriterWriteFormatComment(xmlTextWriterPtr writer
,
870 const char *format
, ...)
875 va_start(ap
, format
);
877 rc
= xmlTextWriterWriteVFormatComment(writer
, format
, ap
);
884 * xmlTextWriterWriteVFormatComment:
885 * @writer: the xmlTextWriterPtr
886 * @format: format string (see printf)
887 * @argptr: pointer to the first member of the variable argument list.
889 * Write an xml comment.
891 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
894 xmlTextWriterWriteVFormatComment(xmlTextWriterPtr writer
,
895 const char *format
, va_list argptr
)
900 if (writer
== NULL
) {
901 xmlWriterErrMsg(writer
, XML_ERR_INTERNAL_ERROR
,
902 "xmlTextWriterWriteVFormatComment : invalid writer!\n");
906 buf
= xmlTextWriterVSprintf(format
, argptr
);
910 rc
= xmlTextWriterWriteComment(writer
, buf
);
917 * xmlTextWriterWriteComment:
918 * @writer: the xmlTextWriterPtr
919 * @content: comment string
921 * Write an xml comment.
923 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
926 xmlTextWriterWriteComment(xmlTextWriterPtr writer
, const xmlChar
* content
)
932 count
= xmlTextWriterStartComment(writer
);
936 count
= xmlTextWriterWriteString(writer
, content
);
940 count
= xmlTextWriterEndComment(writer
);
949 * xmlTextWriterStartElement:
950 * @writer: the xmlTextWriterPtr
951 * @name: element name
953 * Start an xml element.
955 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
958 xmlTextWriterStartElement(xmlTextWriterPtr writer
, const xmlChar
* name
)
963 xmlTextWriterStackEntry
*p
;
965 if ((writer
== NULL
) || (name
== NULL
) || (*name
== '\0'))
969 lk
= xmlListFront(writer
->nodes
);
971 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
974 case XML_TEXTWRITER_PI
:
975 case XML_TEXTWRITER_PI_TEXT
:
977 case XML_TEXTWRITER_NONE
:
979 case XML_TEXTWRITER_ATTRIBUTE
:
980 count
= xmlTextWriterEndAttribute(writer
);
985 case XML_TEXTWRITER_NAME
:
986 /* Output namespace declarations */
987 count
= xmlTextWriterOutputNSDecl(writer
);
991 count
= xmlOutputBufferWriteString(writer
->out
, ">");
997 xmlOutputBufferWriteString(writer
->out
, "\n");
998 p
->state
= XML_TEXTWRITER_TEXT
;
1006 p
= (xmlTextWriterStackEntry
*)
1007 xmlMalloc(sizeof(xmlTextWriterStackEntry
));
1009 xmlWriterErrMsg(writer
, XML_ERR_NO_MEMORY
,
1010 "xmlTextWriterStartElement : out of memory!\n");
1014 p
->name
= xmlStrdup(name
);
1016 xmlWriterErrMsg(writer
, XML_ERR_NO_MEMORY
,
1017 "xmlTextWriterStartElement : out of memory!\n");
1021 p
->state
= XML_TEXTWRITER_NAME
;
1023 xmlListPushFront(writer
->nodes
, p
);
1025 if (writer
->indent
) {
1026 count
= xmlTextWriterWriteIndent(writer
);
1030 count
= xmlOutputBufferWriteString(writer
->out
, "<");
1035 xmlOutputBufferWriteString(writer
->out
, (const char *) p
->name
);
1044 * xmlTextWriterStartElementNS:
1045 * @writer: the xmlTextWriterPtr
1046 * @prefix: namespace prefix or NULL
1047 * @name: element local name
1048 * @namespaceURI: namespace URI or NULL
1050 * Start an xml element with namespace support.
1052 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1055 xmlTextWriterStartElementNS(xmlTextWriterPtr writer
,
1056 const xmlChar
* prefix
, const xmlChar
* name
,
1057 const xmlChar
* namespaceURI
)
1063 if ((writer
== NULL
) || (name
== NULL
) || (*name
== '\0'))
1068 buf
= xmlStrdup(prefix
);
1069 buf
= xmlStrcat(buf
, BAD_CAST
":");
1071 buf
= xmlStrcat(buf
, name
);
1074 count
= xmlTextWriterStartElement(writer
, buf
);
1080 if (namespaceURI
!= 0) {
1081 xmlTextWriterNsStackEntry
*p
= (xmlTextWriterNsStackEntry
*)
1082 xmlMalloc(sizeof(xmlTextWriterNsStackEntry
));
1084 xmlWriterErrMsg(writer
, XML_ERR_NO_MEMORY
,
1085 "xmlTextWriterStartElementNS : out of memory!\n");
1089 buf
= xmlStrdup(BAD_CAST
"xmlns");
1091 buf
= xmlStrcat(buf
, BAD_CAST
":");
1092 buf
= xmlStrcat(buf
, prefix
);
1096 p
->uri
= xmlStrdup(namespaceURI
);
1098 xmlWriterErrMsg(writer
, XML_ERR_NO_MEMORY
,
1099 "xmlTextWriterStartElementNS : out of memory!\n");
1103 p
->elem
= xmlListFront(writer
->nodes
);
1105 xmlListPushFront(writer
->nsstack
, p
);
1112 * xmlTextWriterEndElement:
1113 * @writer: the xmlTextWriterPtr
1115 * End the current xml element.
1117 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1120 xmlTextWriterEndElement(xmlTextWriterPtr writer
)
1125 xmlTextWriterStackEntry
*p
;
1130 lk
= xmlListFront(writer
->nodes
);
1132 xmlListDelete(writer
->nsstack
);
1133 writer
->nsstack
= NULL
;
1137 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
1139 xmlListDelete(writer
->nsstack
);
1140 writer
->nsstack
= NULL
;
1146 case XML_TEXTWRITER_ATTRIBUTE
:
1147 count
= xmlTextWriterEndAttribute(writer
);
1149 xmlListDelete(writer
->nsstack
);
1150 writer
->nsstack
= NULL
;
1155 case XML_TEXTWRITER_NAME
:
1156 /* Output namespace declarations */
1157 count
= xmlTextWriterOutputNSDecl(writer
);
1162 if (writer
->indent
) /* next element needs indent */
1163 writer
->doindent
= 1;
1164 count
= xmlOutputBufferWriteString(writer
->out
, "/>");
1169 case XML_TEXTWRITER_TEXT
:
1170 if ((writer
->indent
) && (writer
->doindent
)) {
1171 count
= xmlTextWriterWriteIndent(writer
);
1173 writer
->doindent
= 1;
1175 writer
->doindent
= 1;
1176 count
= xmlOutputBufferWriteString(writer
->out
, "</");
1180 count
= xmlOutputBufferWriteString(writer
->out
,
1181 (const char *) p
->name
);
1185 count
= xmlOutputBufferWriteString(writer
->out
, ">");
1194 if (writer
->indent
) {
1195 count
= xmlOutputBufferWriteString(writer
->out
, "\n");
1199 xmlListPopFront(writer
->nodes
);
1204 * xmlTextWriterFullEndElement:
1205 * @writer: the xmlTextWriterPtr
1207 * End the current xml element. Writes an end tag even if the element is empty
1209 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1212 xmlTextWriterFullEndElement(xmlTextWriterPtr writer
)
1217 xmlTextWriterStackEntry
*p
;
1222 lk
= xmlListFront(writer
->nodes
);
1226 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
1232 case XML_TEXTWRITER_ATTRIBUTE
:
1233 count
= xmlTextWriterEndAttribute(writer
);
1238 case XML_TEXTWRITER_NAME
:
1239 /* Output namespace declarations */
1240 count
= xmlTextWriterOutputNSDecl(writer
);
1245 count
= xmlOutputBufferWriteString(writer
->out
, ">");
1250 writer
->doindent
= 0;
1252 case XML_TEXTWRITER_TEXT
:
1253 if ((writer
->indent
) && (writer
->doindent
)) {
1254 count
= xmlTextWriterWriteIndent(writer
);
1256 writer
->doindent
= 1;
1258 writer
->doindent
= 1;
1259 count
= xmlOutputBufferWriteString(writer
->out
, "</");
1263 count
= xmlOutputBufferWriteString(writer
->out
,
1264 (const char *) p
->name
);
1268 count
= xmlOutputBufferWriteString(writer
->out
, ">");
1277 if (writer
->indent
) {
1278 count
= xmlOutputBufferWriteString(writer
->out
, "\n");
1282 xmlListPopFront(writer
->nodes
);
1287 * xmlTextWriterWriteFormatRaw:
1288 * @writer: the xmlTextWriterPtr
1289 * @format: format string (see printf)
1290 * @...: extra parameters for the format
1292 * Write a formatted raw xml text.
1294 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1297 xmlTextWriterWriteFormatRaw(xmlTextWriterPtr writer
, const char *format
,
1303 va_start(ap
, format
);
1305 rc
= xmlTextWriterWriteVFormatRaw(writer
, format
, ap
);
1312 * xmlTextWriterWriteVFormatRaw:
1313 * @writer: the xmlTextWriterPtr
1314 * @format: format string (see printf)
1315 * @argptr: pointer to the first member of the variable argument list.
1317 * Write a formatted raw xml text.
1319 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1322 xmlTextWriterWriteVFormatRaw(xmlTextWriterPtr writer
, const char *format
,
1331 buf
= xmlTextWriterVSprintf(format
, argptr
);
1335 rc
= xmlTextWriterWriteRaw(writer
, buf
);
1342 * xmlTextWriterWriteRawLen:
1343 * @writer: the xmlTextWriterPtr
1344 * @content: text string
1345 * @len: length of the text string
1347 * Write an xml text.
1348 * TODO: what about entities and special chars??
1350 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1353 xmlTextWriterWriteRawLen(xmlTextWriterPtr writer
, const xmlChar
* content
,
1359 xmlTextWriterStackEntry
*p
;
1361 if (writer
== NULL
) {
1362 xmlWriterErrMsg(writer
, XML_ERR_INTERNAL_ERROR
,
1363 "xmlTextWriterWriteRawLen : invalid writer!\n");
1367 if ((content
== NULL
) || (len
< 0)) {
1368 xmlWriterErrMsg(writer
, XML_ERR_INTERNAL_ERROR
,
1369 "xmlTextWriterWriteRawLen : invalid content!\n");
1374 lk
= xmlListFront(writer
->nodes
);
1376 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
1377 count
= xmlTextWriterHandleStateDependencies(writer
, p
);
1384 writer
->doindent
= 0;
1386 if (content
!= NULL
) {
1388 xmlOutputBufferWrite(writer
->out
, len
, (const char *) content
);
1398 * xmlTextWriterWriteRaw:
1399 * @writer: the xmlTextWriterPtr
1400 * @content: text string
1402 * Write a raw xml text.
1404 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1407 xmlTextWriterWriteRaw(xmlTextWriterPtr writer
, const xmlChar
* content
)
1409 return xmlTextWriterWriteRawLen(writer
, content
, xmlStrlen(content
));
1413 * xmlTextWriterWriteFormatString:
1414 * @writer: the xmlTextWriterPtr
1415 * @format: format string (see printf)
1416 * @...: extra parameters for the format
1418 * Write a formatted xml text.
1420 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1423 xmlTextWriterWriteFormatString(xmlTextWriterPtr writer
, const char *format
,
1429 if ((writer
== NULL
) || (format
== NULL
))
1432 va_start(ap
, format
);
1434 rc
= xmlTextWriterWriteVFormatString(writer
, format
, ap
);
1441 * xmlTextWriterWriteVFormatString:
1442 * @writer: the xmlTextWriterPtr
1443 * @format: format string (see printf)
1444 * @argptr: pointer to the first member of the variable argument list.
1446 * Write a formatted xml text.
1448 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1451 xmlTextWriterWriteVFormatString(xmlTextWriterPtr writer
,
1452 const char *format
, va_list argptr
)
1457 if ((writer
== NULL
) || (format
== NULL
))
1460 buf
= xmlTextWriterVSprintf(format
, argptr
);
1464 rc
= xmlTextWriterWriteString(writer
, buf
);
1471 * xmlTextWriterWriteString:
1472 * @writer: the xmlTextWriterPtr
1473 * @content: text string
1475 * Write an xml text.
1477 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1480 xmlTextWriterWriteString(xmlTextWriterPtr writer
, const xmlChar
* content
)
1485 xmlTextWriterStackEntry
*p
;
1488 if ((writer
== NULL
) || (content
== NULL
))
1492 buf
= (xmlChar
*) content
;
1493 lk
= xmlListFront(writer
->nodes
);
1495 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
1498 case XML_TEXTWRITER_NAME
:
1499 case XML_TEXTWRITER_TEXT
:
1502 xmlOutputBufferWriteEscape(writer
->out
, content
, NULL
);
1504 buf
= xmlEncodeSpecialChars(NULL
, content
);
1506 case XML_TEXTWRITER_ATTRIBUTE
:
1508 xmlBufAttrSerializeTxtContent(writer
->out
->buffer
,
1509 writer
->doc
, NULL
, content
);
1518 count
= xmlTextWriterWriteRaw(writer
, buf
);
1520 if (buf
!= content
) /* buf was allocated by us, so free it */
1532 * xmlOutputBufferWriteBase64:
1533 * @out: the xmlOutputBufferPtr
1534 * @data: binary data
1535 * @len: the number of bytes to encode
1537 * Write base64 encoded data to an xmlOutputBuffer.
1538 * Adapted from John Walker's base64.c (http://www.fourmilab.ch/).
1540 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1543 xmlOutputBufferWriteBase64(xmlOutputBufferPtr out
, int len
,
1544 const unsigned char *data
)
1546 static unsigned char dtable
[64] =
1547 {'A','B','C','D','E','F','G','H','I','J','K','L','M',
1548 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
1549 'a','b','c','d','e','f','g','h','i','j','k','l','m',
1550 'n','o','p','q','r','s','t','u','v','w','x','y','z',
1551 '0','1','2','3','4','5','6','7','8','9','+','/'};
1558 if ((out
== NULL
) || (len
< 0) || (data
== NULL
))
1566 unsigned char igroup
[3];
1567 unsigned char ogroup
[4];
1571 igroup
[0] = igroup
[1] = igroup
[2] = 0;
1572 for (n
= 0; n
< 3 && i
< len
; n
++, i
++) {
1574 igroup
[n
] = (unsigned char) c
;
1578 ogroup
[0] = dtable
[igroup
[0] >> 2];
1579 ogroup
[1] = dtable
[((igroup
[0] & 3) << 4) | (igroup
[1] >> 4)];
1581 dtable
[((igroup
[1] & 0xF) << 2) | (igroup
[2] >> 6)];
1582 ogroup
[3] = dtable
[igroup
[2] & 0x3F];
1591 if (linelen
>= B64LINELEN
) {
1592 count
= xmlOutputBufferWrite(out
, 2, B64CRLF
);
1598 count
= xmlOutputBufferWrite(out
, 4, (const char *) ogroup
);
1614 * xmlTextWriterWriteBase64:
1615 * @writer: the xmlTextWriterPtr
1616 * @data: binary data
1617 * @start: the position within the data of the first byte to encode
1618 * @len: the number of bytes to encode
1620 * Write an base64 encoded xml text.
1622 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1625 xmlTextWriterWriteBase64(xmlTextWriterPtr writer
, const char *data
,
1631 xmlTextWriterStackEntry
*p
;
1633 if ((writer
== NULL
) || (data
== NULL
) || (start
< 0) || (len
< 0))
1637 lk
= xmlListFront(writer
->nodes
);
1639 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
1641 count
= xmlTextWriterHandleStateDependencies(writer
, p
);
1649 writer
->doindent
= 0;
1652 xmlOutputBufferWriteBase64(writer
->out
, len
,
1653 (unsigned char *) data
+ start
);
1662 * xmlOutputBufferWriteBinHex:
1663 * @out: the xmlOutputBufferPtr
1664 * @data: binary data
1665 * @len: the number of bytes to encode
1667 * Write hqx encoded data to an xmlOutputBuffer.
1670 * Returns the bytes written (may be 0 because of buffering)
1671 * or -1 in case of error
1674 xmlOutputBufferWriteBinHex(xmlOutputBufferPtr out
,
1675 int len
, const unsigned char *data
)
1679 static char hex
[16] =
1680 {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
1683 if ((out
== NULL
) || (data
== NULL
) || (len
< 0)) {
1688 for (i
= 0; i
< len
; i
++) {
1690 xmlOutputBufferWrite(out
, 1,
1691 (const char *) &hex
[data
[i
] >> 4]);
1696 xmlOutputBufferWrite(out
, 1,
1697 (const char *) &hex
[data
[i
] & 0xF]);
1707 * xmlTextWriterWriteBinHex:
1708 * @writer: the xmlTextWriterPtr
1709 * @data: binary data
1710 * @start: the position within the data of the first byte to encode
1711 * @len: the number of bytes to encode
1713 * Write a BinHex encoded xml text.
1715 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1718 xmlTextWriterWriteBinHex(xmlTextWriterPtr writer
, const char *data
,
1724 xmlTextWriterStackEntry
*p
;
1726 if ((writer
== NULL
) || (data
== NULL
) || (start
< 0) || (len
< 0))
1730 lk
= xmlListFront(writer
->nodes
);
1732 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
1734 count
= xmlTextWriterHandleStateDependencies(writer
, p
);
1742 writer
->doindent
= 0;
1745 xmlOutputBufferWriteBinHex(writer
->out
, len
,
1746 (unsigned char *) data
+ start
);
1755 * xmlTextWriterStartAttribute:
1756 * @writer: the xmlTextWriterPtr
1757 * @name: element name
1759 * Start an xml attribute.
1761 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1764 xmlTextWriterStartAttribute(xmlTextWriterPtr writer
, const xmlChar
* name
)
1769 xmlTextWriterStackEntry
*p
;
1771 if ((writer
== NULL
) || (name
== NULL
) || (*name
== '\0'))
1775 lk
= xmlListFront(writer
->nodes
);
1779 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
1784 case XML_TEXTWRITER_ATTRIBUTE
:
1785 count
= xmlTextWriterEndAttribute(writer
);
1790 case XML_TEXTWRITER_NAME
:
1791 count
= xmlOutputBufferWriteString(writer
->out
, " ");
1796 xmlOutputBufferWriteString(writer
->out
,
1797 (const char *) name
);
1801 count
= xmlOutputBufferWriteString(writer
->out
, "=");
1805 count
= xmlOutputBufferWrite(writer
->out
, 1, &writer
->qchar
);
1809 p
->state
= XML_TEXTWRITER_ATTRIBUTE
;
1819 * xmlTextWriterStartAttributeNS:
1820 * @writer: the xmlTextWriterPtr
1821 * @prefix: namespace prefix or NULL
1822 * @name: element local name
1823 * @namespaceURI: namespace URI or NULL
1825 * Start an xml attribute with namespace support.
1827 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1830 xmlTextWriterStartAttributeNS(xmlTextWriterPtr writer
,
1831 const xmlChar
* prefix
, const xmlChar
* name
,
1832 const xmlChar
* namespaceURI
)
1837 xmlTextWriterNsStackEntry
*p
;
1839 if ((writer
== NULL
) || (name
== NULL
) || (*name
== '\0'))
1842 /* Handle namespace first in case of error */
1843 if (namespaceURI
!= 0) {
1844 xmlTextWriterNsStackEntry nsentry
, *curns
;
1846 buf
= xmlStrdup(BAD_CAST
"xmlns");
1848 buf
= xmlStrcat(buf
, BAD_CAST
":");
1849 buf
= xmlStrcat(buf
, prefix
);
1852 nsentry
.prefix
= buf
;
1853 nsentry
.uri
= (xmlChar
*)namespaceURI
;
1854 nsentry
.elem
= xmlListFront(writer
->nodes
);
1856 curns
= (xmlTextWriterNsStackEntry
*)xmlListSearch(writer
->nsstack
,
1858 if ((curns
!= NULL
)) {
1860 if (xmlStrcmp(curns
->uri
, namespaceURI
) == 0) {
1861 /* Namespace already defined on element skip */
1864 /* Prefix mismatch so error out */
1869 /* Do not add namespace decl to list - it is already there */
1871 p
= (xmlTextWriterNsStackEntry
*)
1872 xmlMalloc(sizeof(xmlTextWriterNsStackEntry
));
1874 xmlWriterErrMsg(writer
, XML_ERR_NO_MEMORY
,
1875 "xmlTextWriterStartAttributeNS : out of memory!\n");
1880 p
->uri
= xmlStrdup(namespaceURI
);
1882 xmlWriterErrMsg(writer
, XML_ERR_NO_MEMORY
,
1883 "xmlTextWriterStartAttributeNS : out of memory!\n");
1887 p
->elem
= xmlListFront(writer
->nodes
);
1889 xmlListPushFront(writer
->nsstack
, p
);
1895 buf
= xmlStrdup(prefix
);
1896 buf
= xmlStrcat(buf
, BAD_CAST
":");
1898 buf
= xmlStrcat(buf
, name
);
1901 count
= xmlTextWriterStartAttribute(writer
, buf
);
1911 * xmlTextWriterEndAttribute:
1912 * @writer: the xmlTextWriterPtr
1914 * End the current xml element.
1916 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1919 xmlTextWriterEndAttribute(xmlTextWriterPtr writer
)
1924 xmlTextWriterStackEntry
*p
;
1929 lk
= xmlListFront(writer
->nodes
);
1934 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
1941 case XML_TEXTWRITER_ATTRIBUTE
:
1942 p
->state
= XML_TEXTWRITER_NAME
;
1944 count
= xmlOutputBufferWrite(writer
->out
, 1, &writer
->qchar
);
1958 * xmlTextWriterWriteFormatAttribute:
1959 * @writer: the xmlTextWriterPtr
1960 * @name: attribute name
1961 * @format: format string (see printf)
1962 * @...: extra parameters for the format
1964 * Write a formatted xml attribute.
1966 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1969 xmlTextWriterWriteFormatAttribute(xmlTextWriterPtr writer
,
1970 const xmlChar
* name
, const char *format
,
1976 va_start(ap
, format
);
1978 rc
= xmlTextWriterWriteVFormatAttribute(writer
, name
, format
, ap
);
1985 * xmlTextWriterWriteVFormatAttribute:
1986 * @writer: the xmlTextWriterPtr
1987 * @name: attribute name
1988 * @format: format string (see printf)
1989 * @argptr: pointer to the first member of the variable argument list.
1991 * Write a formatted xml attribute.
1993 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
1996 xmlTextWriterWriteVFormatAttribute(xmlTextWriterPtr writer
,
1997 const xmlChar
* name
,
1998 const char *format
, va_list argptr
)
2006 buf
= xmlTextWriterVSprintf(format
, argptr
);
2010 rc
= xmlTextWriterWriteAttribute(writer
, name
, buf
);
2017 * xmlTextWriterWriteAttribute:
2018 * @writer: the xmlTextWriterPtr
2019 * @name: attribute name
2020 * @content: attribute content
2022 * Write an xml attribute.
2024 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2027 xmlTextWriterWriteAttribute(xmlTextWriterPtr writer
, const xmlChar
* name
,
2028 const xmlChar
* content
)
2034 count
= xmlTextWriterStartAttribute(writer
, name
);
2038 count
= xmlTextWriterWriteString(writer
, content
);
2042 count
= xmlTextWriterEndAttribute(writer
);
2051 * xmlTextWriterWriteFormatAttributeNS:
2052 * @writer: the xmlTextWriterPtr
2053 * @prefix: namespace prefix
2054 * @name: attribute local name
2055 * @namespaceURI: namespace URI
2056 * @format: format string (see printf)
2057 * @...: extra parameters for the format
2059 * Write a formatted xml attribute.with namespace support
2061 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2064 xmlTextWriterWriteFormatAttributeNS(xmlTextWriterPtr writer
,
2065 const xmlChar
* prefix
,
2066 const xmlChar
* name
,
2067 const xmlChar
* namespaceURI
,
2068 const char *format
, ...)
2073 va_start(ap
, format
);
2075 rc
= xmlTextWriterWriteVFormatAttributeNS(writer
, prefix
, name
,
2076 namespaceURI
, format
, ap
);
2083 * xmlTextWriterWriteVFormatAttributeNS:
2084 * @writer: the xmlTextWriterPtr
2085 * @prefix: namespace prefix
2086 * @name: attribute local name
2087 * @namespaceURI: namespace URI
2088 * @format: format string (see printf)
2089 * @argptr: pointer to the first member of the variable argument list.
2091 * Write a formatted xml attribute.with namespace support
2093 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2096 xmlTextWriterWriteVFormatAttributeNS(xmlTextWriterPtr writer
,
2097 const xmlChar
* prefix
,
2098 const xmlChar
* name
,
2099 const xmlChar
* namespaceURI
,
2100 const char *format
, va_list argptr
)
2108 buf
= xmlTextWriterVSprintf(format
, argptr
);
2112 rc
= xmlTextWriterWriteAttributeNS(writer
, prefix
, name
, namespaceURI
,
2120 * xmlTextWriterWriteAttributeNS:
2121 * @writer: the xmlTextWriterPtr
2122 * @prefix: namespace prefix
2123 * @name: attribute local name
2124 * @namespaceURI: namespace URI
2125 * @content: attribute content
2127 * Write an xml attribute.
2129 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2132 xmlTextWriterWriteAttributeNS(xmlTextWriterPtr writer
,
2133 const xmlChar
* prefix
, const xmlChar
* name
,
2134 const xmlChar
* namespaceURI
,
2135 const xmlChar
* content
)
2140 if ((writer
== NULL
) || (name
== NULL
) || (*name
== '\0'))
2144 count
= xmlTextWriterStartAttributeNS(writer
, prefix
, name
, namespaceURI
);
2148 count
= xmlTextWriterWriteString(writer
, content
);
2152 count
= xmlTextWriterEndAttribute(writer
);
2161 * xmlTextWriterWriteFormatElement:
2162 * @writer: the xmlTextWriterPtr
2163 * @name: element name
2164 * @format: format string (see printf)
2165 * @...: extra parameters for the format
2167 * Write a formatted xml element.
2169 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2172 xmlTextWriterWriteFormatElement(xmlTextWriterPtr writer
,
2173 const xmlChar
* name
, const char *format
,
2179 va_start(ap
, format
);
2181 rc
= xmlTextWriterWriteVFormatElement(writer
, name
, format
, ap
);
2188 * xmlTextWriterWriteVFormatElement:
2189 * @writer: the xmlTextWriterPtr
2190 * @name: element name
2191 * @format: format string (see printf)
2192 * @argptr: pointer to the first member of the variable argument list.
2194 * Write a formatted xml element.
2196 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2199 xmlTextWriterWriteVFormatElement(xmlTextWriterPtr writer
,
2200 const xmlChar
* name
, const char *format
,
2209 buf
= xmlTextWriterVSprintf(format
, argptr
);
2213 rc
= xmlTextWriterWriteElement(writer
, name
, buf
);
2220 * xmlTextWriterWriteElement:
2221 * @writer: the xmlTextWriterPtr
2222 * @name: element name
2223 * @content: element content
2225 * Write an xml element.
2227 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2230 xmlTextWriterWriteElement(xmlTextWriterPtr writer
, const xmlChar
* name
,
2231 const xmlChar
* content
)
2237 count
= xmlTextWriterStartElement(writer
, name
);
2241 count
= xmlTextWriterWriteString(writer
, content
);
2245 count
= xmlTextWriterEndElement(writer
);
2254 * xmlTextWriterWriteFormatElementNS:
2255 * @writer: the xmlTextWriterPtr
2256 * @prefix: namespace prefix
2257 * @name: element local name
2258 * @namespaceURI: namespace URI
2259 * @format: format string (see printf)
2260 * @...: extra parameters for the format
2262 * Write a formatted xml element with namespace support.
2264 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2267 xmlTextWriterWriteFormatElementNS(xmlTextWriterPtr writer
,
2268 const xmlChar
* prefix
,
2269 const xmlChar
* name
,
2270 const xmlChar
* namespaceURI
,
2271 const char *format
, ...)
2276 va_start(ap
, format
);
2278 rc
= xmlTextWriterWriteVFormatElementNS(writer
, prefix
, name
,
2279 namespaceURI
, format
, ap
);
2286 * xmlTextWriterWriteVFormatElementNS:
2287 * @writer: the xmlTextWriterPtr
2288 * @prefix: namespace prefix
2289 * @name: element local name
2290 * @namespaceURI: namespace URI
2291 * @format: format string (see printf)
2292 * @argptr: pointer to the first member of the variable argument list.
2294 * Write a formatted xml element with namespace support.
2296 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2299 xmlTextWriterWriteVFormatElementNS(xmlTextWriterPtr writer
,
2300 const xmlChar
* prefix
,
2301 const xmlChar
* name
,
2302 const xmlChar
* namespaceURI
,
2303 const char *format
, va_list argptr
)
2311 buf
= xmlTextWriterVSprintf(format
, argptr
);
2315 rc
= xmlTextWriterWriteElementNS(writer
, prefix
, name
, namespaceURI
,
2323 * xmlTextWriterWriteElementNS:
2324 * @writer: the xmlTextWriterPtr
2325 * @prefix: namespace prefix
2326 * @name: element local name
2327 * @namespaceURI: namespace URI
2328 * @content: element content
2330 * Write an xml element with namespace support.
2332 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2335 xmlTextWriterWriteElementNS(xmlTextWriterPtr writer
,
2336 const xmlChar
* prefix
, const xmlChar
* name
,
2337 const xmlChar
* namespaceURI
,
2338 const xmlChar
* content
)
2343 if ((writer
== NULL
) || (name
== NULL
) || (*name
== '\0'))
2348 xmlTextWriterStartElementNS(writer
, prefix
, name
, namespaceURI
);
2352 count
= xmlTextWriterWriteString(writer
, content
);
2356 count
= xmlTextWriterEndElement(writer
);
2365 * xmlTextWriterStartPI:
2366 * @writer: the xmlTextWriterPtr
2367 * @target: PI target
2371 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2374 xmlTextWriterStartPI(xmlTextWriterPtr writer
, const xmlChar
* target
)
2379 xmlTextWriterStackEntry
*p
;
2381 if ((writer
== NULL
) || (target
== NULL
) || (*target
== '\0'))
2384 if (xmlStrcasecmp(target
, (const xmlChar
*) "xml") == 0) {
2385 xmlWriterErrMsg(writer
, XML_ERR_INTERNAL_ERROR
,
2386 "xmlTextWriterStartPI : target name [Xx][Mm][Ll] is reserved for xml standardization!\n");
2391 lk
= xmlListFront(writer
->nodes
);
2393 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
2396 case XML_TEXTWRITER_ATTRIBUTE
:
2397 count
= xmlTextWriterEndAttribute(writer
);
2402 case XML_TEXTWRITER_NAME
:
2403 /* Output namespace declarations */
2404 count
= xmlTextWriterOutputNSDecl(writer
);
2408 count
= xmlOutputBufferWriteString(writer
->out
, ">");
2412 p
->state
= XML_TEXTWRITER_TEXT
;
2414 case XML_TEXTWRITER_NONE
:
2415 case XML_TEXTWRITER_TEXT
:
2416 case XML_TEXTWRITER_DTD
:
2418 case XML_TEXTWRITER_PI
:
2419 case XML_TEXTWRITER_PI_TEXT
:
2420 xmlWriterErrMsg(writer
, XML_ERR_INTERNAL_ERROR
,
2421 "xmlTextWriterStartPI : nested PI!\n");
2429 p
= (xmlTextWriterStackEntry
*)
2430 xmlMalloc(sizeof(xmlTextWriterStackEntry
));
2432 xmlWriterErrMsg(writer
, XML_ERR_NO_MEMORY
,
2433 "xmlTextWriterStartPI : out of memory!\n");
2437 p
->name
= xmlStrdup(target
);
2439 xmlWriterErrMsg(writer
, XML_ERR_NO_MEMORY
,
2440 "xmlTextWriterStartPI : out of memory!\n");
2444 p
->state
= XML_TEXTWRITER_PI
;
2446 xmlListPushFront(writer
->nodes
, p
);
2448 count
= xmlOutputBufferWriteString(writer
->out
, "<?");
2453 xmlOutputBufferWriteString(writer
->out
, (const char *) p
->name
);
2462 * xmlTextWriterEndPI:
2463 * @writer: the xmlTextWriterPtr
2465 * End the current xml PI.
2467 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2470 xmlTextWriterEndPI(xmlTextWriterPtr writer
)
2475 xmlTextWriterStackEntry
*p
;
2480 lk
= xmlListFront(writer
->nodes
);
2484 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
2490 case XML_TEXTWRITER_PI
:
2491 case XML_TEXTWRITER_PI_TEXT
:
2492 count
= xmlOutputBufferWriteString(writer
->out
, "?>");
2501 if (writer
->indent
) {
2502 count
= xmlOutputBufferWriteString(writer
->out
, "\n");
2508 xmlListPopFront(writer
->nodes
);
2513 * xmlTextWriterWriteFormatPI:
2514 * @writer: the xmlTextWriterPtr
2515 * @target: PI target
2516 * @format: format string (see printf)
2517 * @...: extra parameters for the format
2519 * Write a formatted PI.
2521 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2524 xmlTextWriterWriteFormatPI(xmlTextWriterPtr writer
, const xmlChar
* target
,
2525 const char *format
, ...)
2530 va_start(ap
, format
);
2532 rc
= xmlTextWriterWriteVFormatPI(writer
, target
, format
, ap
);
2539 * xmlTextWriterWriteVFormatPI:
2540 * @writer: the xmlTextWriterPtr
2541 * @target: PI target
2542 * @format: format string (see printf)
2543 * @argptr: pointer to the first member of the variable argument list.
2545 * Write a formatted xml PI.
2547 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2550 xmlTextWriterWriteVFormatPI(xmlTextWriterPtr writer
,
2551 const xmlChar
* target
, const char *format
,
2560 buf
= xmlTextWriterVSprintf(format
, argptr
);
2564 rc
= xmlTextWriterWritePI(writer
, target
, buf
);
2571 * xmlTextWriterWritePI:
2572 * @writer: the xmlTextWriterPtr
2573 * @target: PI target
2574 * @content: PI content
2578 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2581 xmlTextWriterWritePI(xmlTextWriterPtr writer
, const xmlChar
* target
,
2582 const xmlChar
* content
)
2588 count
= xmlTextWriterStartPI(writer
, target
);
2593 count
= xmlTextWriterWriteString(writer
, content
);
2598 count
= xmlTextWriterEndPI(writer
);
2607 * xmlTextWriterStartCDATA:
2608 * @writer: the xmlTextWriterPtr
2610 * Start an xml CDATA section.
2612 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2615 xmlTextWriterStartCDATA(xmlTextWriterPtr writer
)
2620 xmlTextWriterStackEntry
*p
;
2626 lk
= xmlListFront(writer
->nodes
);
2628 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
2631 case XML_TEXTWRITER_NONE
:
2632 case XML_TEXTWRITER_TEXT
:
2633 case XML_TEXTWRITER_PI
:
2634 case XML_TEXTWRITER_PI_TEXT
:
2636 case XML_TEXTWRITER_ATTRIBUTE
:
2637 count
= xmlTextWriterEndAttribute(writer
);
2642 case XML_TEXTWRITER_NAME
:
2643 /* Output namespace declarations */
2644 count
= xmlTextWriterOutputNSDecl(writer
);
2648 count
= xmlOutputBufferWriteString(writer
->out
, ">");
2652 p
->state
= XML_TEXTWRITER_TEXT
;
2654 case XML_TEXTWRITER_CDATA
:
2655 xmlWriterErrMsg(writer
, XML_ERR_INTERNAL_ERROR
,
2656 "xmlTextWriterStartCDATA : CDATA not allowed in this context!\n");
2664 p
= (xmlTextWriterStackEntry
*)
2665 xmlMalloc(sizeof(xmlTextWriterStackEntry
));
2667 xmlWriterErrMsg(writer
, XML_ERR_NO_MEMORY
,
2668 "xmlTextWriterStartCDATA : out of memory!\n");
2673 p
->state
= XML_TEXTWRITER_CDATA
;
2675 xmlListPushFront(writer
->nodes
, p
);
2677 count
= xmlOutputBufferWriteString(writer
->out
, "<![CDATA[");
2686 * xmlTextWriterEndCDATA:
2687 * @writer: the xmlTextWriterPtr
2689 * End an xml CDATA section.
2691 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2694 xmlTextWriterEndCDATA(xmlTextWriterPtr writer
)
2699 xmlTextWriterStackEntry
*p
;
2704 lk
= xmlListFront(writer
->nodes
);
2708 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
2714 case XML_TEXTWRITER_CDATA
:
2715 count
= xmlOutputBufferWriteString(writer
->out
, "]]>");
2724 xmlListPopFront(writer
->nodes
);
2729 * xmlTextWriterWriteFormatCDATA:
2730 * @writer: the xmlTextWriterPtr
2731 * @format: format string (see printf)
2732 * @...: extra parameters for the format
2734 * Write a formatted xml CDATA.
2736 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2739 xmlTextWriterWriteFormatCDATA(xmlTextWriterPtr writer
, const char *format
,
2745 va_start(ap
, format
);
2747 rc
= xmlTextWriterWriteVFormatCDATA(writer
, format
, ap
);
2754 * xmlTextWriterWriteVFormatCDATA:
2755 * @writer: the xmlTextWriterPtr
2756 * @format: format string (see printf)
2757 * @argptr: pointer to the first member of the variable argument list.
2759 * Write a formatted xml CDATA.
2761 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2764 xmlTextWriterWriteVFormatCDATA(xmlTextWriterPtr writer
, const char *format
,
2773 buf
= xmlTextWriterVSprintf(format
, argptr
);
2777 rc
= xmlTextWriterWriteCDATA(writer
, buf
);
2784 * xmlTextWriterWriteCDATA:
2785 * @writer: the xmlTextWriterPtr
2786 * @content: CDATA content
2788 * Write an xml CDATA.
2790 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2793 xmlTextWriterWriteCDATA(xmlTextWriterPtr writer
, const xmlChar
* content
)
2799 count
= xmlTextWriterStartCDATA(writer
);
2804 count
= xmlTextWriterWriteString(writer
, content
);
2809 count
= xmlTextWriterEndCDATA(writer
);
2818 * xmlTextWriterStartDTD:
2819 * @writer: the xmlTextWriterPtr
2820 * @name: the name of the DTD
2821 * @pubid: the public identifier, which is an alternative to the system identifier
2822 * @sysid: the system identifier, which is the URI of the DTD
2826 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2829 xmlTextWriterStartDTD(xmlTextWriterPtr writer
,
2830 const xmlChar
* name
,
2831 const xmlChar
* pubid
, const xmlChar
* sysid
)
2836 xmlTextWriterStackEntry
*p
;
2838 if (writer
== NULL
|| name
== NULL
|| *name
== '\0')
2842 lk
= xmlListFront(writer
->nodes
);
2843 if ((lk
!= NULL
) && (xmlLinkGetData(lk
) != NULL
)) {
2844 xmlWriterErrMsg(writer
, XML_ERR_INTERNAL_ERROR
,
2845 "xmlTextWriterStartDTD : DTD allowed only in prolog!\n");
2849 p
= (xmlTextWriterStackEntry
*)
2850 xmlMalloc(sizeof(xmlTextWriterStackEntry
));
2852 xmlWriterErrMsg(writer
, XML_ERR_NO_MEMORY
,
2853 "xmlTextWriterStartDTD : out of memory!\n");
2857 p
->name
= xmlStrdup(name
);
2859 xmlWriterErrMsg(writer
, XML_ERR_NO_MEMORY
,
2860 "xmlTextWriterStartDTD : out of memory!\n");
2864 p
->state
= XML_TEXTWRITER_DTD
;
2866 xmlListPushFront(writer
->nodes
, p
);
2868 count
= xmlOutputBufferWriteString(writer
->out
, "<!DOCTYPE ");
2872 count
= xmlOutputBufferWriteString(writer
->out
, (const char *) name
);
2879 xmlWriterErrMsg(writer
, XML_ERR_INTERNAL_ERROR
,
2880 "xmlTextWriterStartDTD : system identifier needed!\n");
2885 count
= xmlOutputBufferWrite(writer
->out
, 1, "\n");
2887 count
= xmlOutputBufferWrite(writer
->out
, 1, " ");
2892 count
= xmlOutputBufferWriteString(writer
->out
, "PUBLIC ");
2897 count
= xmlOutputBufferWrite(writer
->out
, 1, &writer
->qchar
);
2903 xmlOutputBufferWriteString(writer
->out
, (const char *) pubid
);
2908 count
= xmlOutputBufferWrite(writer
->out
, 1, &writer
->qchar
);
2917 count
= xmlOutputBufferWrite(writer
->out
, 1, "\n");
2919 count
= xmlOutputBufferWrite(writer
->out
, 1, " ");
2923 count
= xmlOutputBufferWriteString(writer
->out
, "SYSTEM ");
2929 count
= xmlOutputBufferWriteString(writer
->out
, "\n ");
2931 count
= xmlOutputBufferWrite(writer
->out
, 1, " ");
2937 count
= xmlOutputBufferWrite(writer
->out
, 1, &writer
->qchar
);
2943 xmlOutputBufferWriteString(writer
->out
, (const char *) sysid
);
2948 count
= xmlOutputBufferWrite(writer
->out
, 1, &writer
->qchar
);
2958 * xmlTextWriterEndDTD:
2959 * @writer: the xmlTextWriterPtr
2963 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
2966 xmlTextWriterEndDTD(xmlTextWriterPtr writer
)
2972 xmlTextWriterStackEntry
*p
;
2980 lk
= xmlListFront(writer
->nodes
);
2983 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
2987 case XML_TEXTWRITER_DTD_TEXT
:
2988 count
= xmlOutputBufferWriteString(writer
->out
, "]");
2993 case XML_TEXTWRITER_DTD
:
2994 count
= xmlOutputBufferWriteString(writer
->out
, ">");
2996 if (writer
->indent
) {
3000 count
= xmlOutputBufferWriteString(writer
->out
, "\n");
3003 xmlListPopFront(writer
->nodes
);
3005 case XML_TEXTWRITER_DTD_ELEM
:
3006 case XML_TEXTWRITER_DTD_ELEM_TEXT
:
3007 count
= xmlTextWriterEndDTDElement(writer
);
3009 case XML_TEXTWRITER_DTD_ATTL
:
3010 case XML_TEXTWRITER_DTD_ATTL_TEXT
:
3011 count
= xmlTextWriterEndDTDAttlist(writer
);
3013 case XML_TEXTWRITER_DTD_ENTY
:
3014 case XML_TEXTWRITER_DTD_PENT
:
3015 case XML_TEXTWRITER_DTD_ENTY_TEXT
:
3016 count
= xmlTextWriterEndDTDEntity(writer
);
3018 case XML_TEXTWRITER_COMMENT
:
3019 count
= xmlTextWriterEndComment(writer
);
3035 * xmlTextWriterWriteFormatDTD:
3036 * @writer: the xmlTextWriterPtr
3037 * @name: the name of the DTD
3038 * @pubid: the public identifier, which is an alternative to the system identifier
3039 * @sysid: the system identifier, which is the URI of the DTD
3040 * @format: format string (see printf)
3041 * @...: extra parameters for the format
3043 * Write a DTD with a formatted markup declarations part.
3045 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3048 xmlTextWriterWriteFormatDTD(xmlTextWriterPtr writer
,
3049 const xmlChar
* name
,
3050 const xmlChar
* pubid
,
3051 const xmlChar
* sysid
, const char *format
, ...)
3056 va_start(ap
, format
);
3058 rc
= xmlTextWriterWriteVFormatDTD(writer
, name
, pubid
, sysid
, format
,
3066 * xmlTextWriterWriteVFormatDTD:
3067 * @writer: the xmlTextWriterPtr
3068 * @name: the name of the DTD
3069 * @pubid: the public identifier, which is an alternative to the system identifier
3070 * @sysid: the system identifier, which is the URI of the DTD
3071 * @format: format string (see printf)
3072 * @argptr: pointer to the first member of the variable argument list.
3074 * Write a DTD with a formatted markup declarations part.
3076 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3079 xmlTextWriterWriteVFormatDTD(xmlTextWriterPtr writer
,
3080 const xmlChar
* name
,
3081 const xmlChar
* pubid
,
3082 const xmlChar
* sysid
,
3083 const char *format
, va_list argptr
)
3091 buf
= xmlTextWriterVSprintf(format
, argptr
);
3095 rc
= xmlTextWriterWriteDTD(writer
, name
, pubid
, sysid
, buf
);
3102 * xmlTextWriterWriteDTD:
3103 * @writer: the xmlTextWriterPtr
3104 * @name: the name of the DTD
3105 * @pubid: the public identifier, which is an alternative to the system identifier
3106 * @sysid: the system identifier, which is the URI of the DTD
3107 * @subset: string content of the DTD
3111 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3114 xmlTextWriterWriteDTD(xmlTextWriterPtr writer
,
3115 const xmlChar
* name
,
3116 const xmlChar
* pubid
,
3117 const xmlChar
* sysid
, const xmlChar
* subset
)
3123 count
= xmlTextWriterStartDTD(writer
, name
, pubid
, sysid
);
3128 count
= xmlTextWriterWriteString(writer
, subset
);
3133 count
= xmlTextWriterEndDTD(writer
);
3142 * xmlTextWriterStartDTDElement:
3143 * @writer: the xmlTextWriterPtr
3144 * @name: the name of the DTD element
3146 * Start an xml DTD element.
3148 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3151 xmlTextWriterStartDTDElement(xmlTextWriterPtr writer
, const xmlChar
* name
)
3156 xmlTextWriterStackEntry
*p
;
3158 if (writer
== NULL
|| name
== NULL
|| *name
== '\0')
3162 lk
= xmlListFront(writer
->nodes
);
3167 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
3170 case XML_TEXTWRITER_DTD
:
3171 count
= xmlOutputBufferWriteString(writer
->out
, " [");
3175 if (writer
->indent
) {
3176 count
= xmlOutputBufferWriteString(writer
->out
, "\n");
3181 p
->state
= XML_TEXTWRITER_DTD_TEXT
;
3183 case XML_TEXTWRITER_DTD_TEXT
:
3184 case XML_TEXTWRITER_NONE
:
3191 p
= (xmlTextWriterStackEntry
*)
3192 xmlMalloc(sizeof(xmlTextWriterStackEntry
));
3194 xmlWriterErrMsg(writer
, XML_ERR_NO_MEMORY
,
3195 "xmlTextWriterStartDTDElement : out of memory!\n");
3199 p
->name
= xmlStrdup(name
);
3201 xmlWriterErrMsg(writer
, XML_ERR_NO_MEMORY
,
3202 "xmlTextWriterStartDTDElement : out of memory!\n");
3206 p
->state
= XML_TEXTWRITER_DTD_ELEM
;
3208 xmlListPushFront(writer
->nodes
, p
);
3210 if (writer
->indent
) {
3211 count
= xmlTextWriterWriteIndent(writer
);
3217 count
= xmlOutputBufferWriteString(writer
->out
, "<!ELEMENT ");
3221 count
= xmlOutputBufferWriteString(writer
->out
, (const char *) name
);
3230 * xmlTextWriterEndDTDElement:
3231 * @writer: the xmlTextWriterPtr
3233 * End an xml DTD element.
3235 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3238 xmlTextWriterEndDTDElement(xmlTextWriterPtr writer
)
3243 xmlTextWriterStackEntry
*p
;
3249 lk
= xmlListFront(writer
->nodes
);
3253 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
3258 case XML_TEXTWRITER_DTD_ELEM
:
3259 case XML_TEXTWRITER_DTD_ELEM_TEXT
:
3260 count
= xmlOutputBufferWriteString(writer
->out
, ">");
3269 if (writer
->indent
) {
3270 count
= xmlOutputBufferWriteString(writer
->out
, "\n");
3276 xmlListPopFront(writer
->nodes
);
3281 * xmlTextWriterWriteFormatDTDElement:
3282 * @writer: the xmlTextWriterPtr
3283 * @name: the name of the DTD element
3284 * @format: format string (see printf)
3285 * @...: extra parameters for the format
3287 * Write a formatted DTD element.
3289 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3292 xmlTextWriterWriteFormatDTDElement(xmlTextWriterPtr writer
,
3293 const xmlChar
* name
,
3294 const char *format
, ...)
3299 va_start(ap
, format
);
3301 rc
= xmlTextWriterWriteVFormatDTDElement(writer
, name
, format
, ap
);
3308 * xmlTextWriterWriteVFormatDTDElement:
3309 * @writer: the xmlTextWriterPtr
3310 * @name: the name of the DTD element
3311 * @format: format string (see printf)
3312 * @argptr: pointer to the first member of the variable argument list.
3314 * Write a formatted DTD element.
3316 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3319 xmlTextWriterWriteVFormatDTDElement(xmlTextWriterPtr writer
,
3320 const xmlChar
* name
,
3321 const char *format
, va_list argptr
)
3329 buf
= xmlTextWriterVSprintf(format
, argptr
);
3333 rc
= xmlTextWriterWriteDTDElement(writer
, name
, buf
);
3340 * xmlTextWriterWriteDTDElement:
3341 * @writer: the xmlTextWriterPtr
3342 * @name: the name of the DTD element
3343 * @content: content of the element
3345 * Write a DTD element.
3347 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3350 xmlTextWriterWriteDTDElement(xmlTextWriterPtr writer
,
3351 const xmlChar
* name
, const xmlChar
* content
)
3356 if (content
== NULL
)
3360 count
= xmlTextWriterStartDTDElement(writer
, name
);
3365 count
= xmlTextWriterWriteString(writer
, content
);
3370 count
= xmlTextWriterEndDTDElement(writer
);
3379 * xmlTextWriterStartDTDAttlist:
3380 * @writer: the xmlTextWriterPtr
3381 * @name: the name of the DTD ATTLIST
3383 * Start an xml DTD ATTLIST.
3385 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3388 xmlTextWriterStartDTDAttlist(xmlTextWriterPtr writer
, const xmlChar
* name
)
3393 xmlTextWriterStackEntry
*p
;
3395 if (writer
== NULL
|| name
== NULL
|| *name
== '\0')
3399 lk
= xmlListFront(writer
->nodes
);
3404 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
3407 case XML_TEXTWRITER_DTD
:
3408 count
= xmlOutputBufferWriteString(writer
->out
, " [");
3412 if (writer
->indent
) {
3413 count
= xmlOutputBufferWriteString(writer
->out
, "\n");
3418 p
->state
= XML_TEXTWRITER_DTD_TEXT
;
3420 case XML_TEXTWRITER_DTD_TEXT
:
3421 case XML_TEXTWRITER_NONE
:
3428 p
= (xmlTextWriterStackEntry
*)
3429 xmlMalloc(sizeof(xmlTextWriterStackEntry
));
3431 xmlWriterErrMsg(writer
, XML_ERR_NO_MEMORY
,
3432 "xmlTextWriterStartDTDAttlist : out of memory!\n");
3436 p
->name
= xmlStrdup(name
);
3438 xmlWriterErrMsg(writer
, XML_ERR_NO_MEMORY
,
3439 "xmlTextWriterStartDTDAttlist : out of memory!\n");
3443 p
->state
= XML_TEXTWRITER_DTD_ATTL
;
3445 xmlListPushFront(writer
->nodes
, p
);
3447 if (writer
->indent
) {
3448 count
= xmlTextWriterWriteIndent(writer
);
3454 count
= xmlOutputBufferWriteString(writer
->out
, "<!ATTLIST ");
3458 count
= xmlOutputBufferWriteString(writer
->out
, (const char *) name
);
3467 * xmlTextWriterEndDTDAttlist:
3468 * @writer: the xmlTextWriterPtr
3470 * End an xml DTD attribute list.
3472 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3475 xmlTextWriterEndDTDAttlist(xmlTextWriterPtr writer
)
3480 xmlTextWriterStackEntry
*p
;
3486 lk
= xmlListFront(writer
->nodes
);
3490 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
3495 case XML_TEXTWRITER_DTD_ATTL
:
3496 case XML_TEXTWRITER_DTD_ATTL_TEXT
:
3497 count
= xmlOutputBufferWriteString(writer
->out
, ">");
3506 if (writer
->indent
) {
3507 count
= xmlOutputBufferWriteString(writer
->out
, "\n");
3513 xmlListPopFront(writer
->nodes
);
3518 * xmlTextWriterWriteFormatDTDAttlist:
3519 * @writer: the xmlTextWriterPtr
3520 * @name: the name of the DTD ATTLIST
3521 * @format: format string (see printf)
3522 * @...: extra parameters for the format
3524 * Write a formatted DTD ATTLIST.
3526 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3529 xmlTextWriterWriteFormatDTDAttlist(xmlTextWriterPtr writer
,
3530 const xmlChar
* name
,
3531 const char *format
, ...)
3536 va_start(ap
, format
);
3538 rc
= xmlTextWriterWriteVFormatDTDAttlist(writer
, name
, format
, ap
);
3545 * xmlTextWriterWriteVFormatDTDAttlist:
3546 * @writer: the xmlTextWriterPtr
3547 * @name: the name of the DTD ATTLIST
3548 * @format: format string (see printf)
3549 * @argptr: pointer to the first member of the variable argument list.
3551 * Write a formatted DTD ATTLIST.
3553 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3556 xmlTextWriterWriteVFormatDTDAttlist(xmlTextWriterPtr writer
,
3557 const xmlChar
* name
,
3558 const char *format
, va_list argptr
)
3566 buf
= xmlTextWriterVSprintf(format
, argptr
);
3570 rc
= xmlTextWriterWriteDTDAttlist(writer
, name
, buf
);
3577 * xmlTextWriterWriteDTDAttlist:
3578 * @writer: the xmlTextWriterPtr
3579 * @name: the name of the DTD ATTLIST
3580 * @content: content of the ATTLIST
3582 * Write a DTD ATTLIST.
3584 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3587 xmlTextWriterWriteDTDAttlist(xmlTextWriterPtr writer
,
3588 const xmlChar
* name
, const xmlChar
* content
)
3593 if (content
== NULL
)
3597 count
= xmlTextWriterStartDTDAttlist(writer
, name
);
3602 count
= xmlTextWriterWriteString(writer
, content
);
3607 count
= xmlTextWriterEndDTDAttlist(writer
);
3616 * xmlTextWriterStartDTDEntity:
3617 * @writer: the xmlTextWriterPtr
3618 * @pe: TRUE if this is a parameter entity, FALSE if not
3619 * @name: the name of the DTD ATTLIST
3621 * Start an xml DTD ATTLIST.
3623 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3626 xmlTextWriterStartDTDEntity(xmlTextWriterPtr writer
,
3627 int pe
, const xmlChar
* name
)
3632 xmlTextWriterStackEntry
*p
;
3634 if (writer
== NULL
|| name
== NULL
|| *name
== '\0')
3638 lk
= xmlListFront(writer
->nodes
);
3641 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
3644 case XML_TEXTWRITER_DTD
:
3645 count
= xmlOutputBufferWriteString(writer
->out
, " [");
3649 if (writer
->indent
) {
3651 xmlOutputBufferWriteString(writer
->out
, "\n");
3656 p
->state
= XML_TEXTWRITER_DTD_TEXT
;
3658 case XML_TEXTWRITER_DTD_TEXT
:
3659 case XML_TEXTWRITER_NONE
:
3667 p
= (xmlTextWriterStackEntry
*)
3668 xmlMalloc(sizeof(xmlTextWriterStackEntry
));
3670 xmlWriterErrMsg(writer
, XML_ERR_NO_MEMORY
,
3671 "xmlTextWriterStartDTDElement : out of memory!\n");
3675 p
->name
= xmlStrdup(name
);
3677 xmlWriterErrMsg(writer
, XML_ERR_NO_MEMORY
,
3678 "xmlTextWriterStartDTDElement : out of memory!\n");
3684 p
->state
= XML_TEXTWRITER_DTD_PENT
;
3686 p
->state
= XML_TEXTWRITER_DTD_ENTY
;
3688 xmlListPushFront(writer
->nodes
, p
);
3690 if (writer
->indent
) {
3691 count
= xmlTextWriterWriteIndent(writer
);
3697 count
= xmlOutputBufferWriteString(writer
->out
, "<!ENTITY ");
3703 count
= xmlOutputBufferWriteString(writer
->out
, "% ");
3709 count
= xmlOutputBufferWriteString(writer
->out
, (const char *) name
);
3718 * xmlTextWriterEndDTDEntity:
3719 * @writer: the xmlTextWriterPtr
3721 * End an xml DTD entity.
3723 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3726 xmlTextWriterEndDTDEntity(xmlTextWriterPtr writer
)
3731 xmlTextWriterStackEntry
*p
;
3737 lk
= xmlListFront(writer
->nodes
);
3741 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
3746 case XML_TEXTWRITER_DTD_ENTY_TEXT
:
3747 count
= xmlOutputBufferWrite(writer
->out
, 1, &writer
->qchar
);
3751 case XML_TEXTWRITER_DTD_ENTY
:
3752 case XML_TEXTWRITER_DTD_PENT
:
3753 count
= xmlOutputBufferWriteString(writer
->out
, ">");
3762 if (writer
->indent
) {
3763 count
= xmlOutputBufferWriteString(writer
->out
, "\n");
3769 xmlListPopFront(writer
->nodes
);
3774 * xmlTextWriterWriteFormatDTDInternalEntity:
3775 * @writer: the xmlTextWriterPtr
3776 * @pe: TRUE if this is a parameter entity, FALSE if not
3777 * @name: the name of the DTD entity
3778 * @format: format string (see printf)
3779 * @...: extra parameters for the format
3781 * Write a formatted DTD internal entity.
3783 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3786 xmlTextWriterWriteFormatDTDInternalEntity(xmlTextWriterPtr writer
,
3788 const xmlChar
* name
,
3789 const char *format
, ...)
3794 va_start(ap
, format
);
3796 rc
= xmlTextWriterWriteVFormatDTDInternalEntity(writer
, pe
, name
,
3804 * xmlTextWriterWriteVFormatDTDInternalEntity:
3805 * @writer: the xmlTextWriterPtr
3806 * @pe: TRUE if this is a parameter entity, FALSE if not
3807 * @name: the name of the DTD entity
3808 * @format: format string (see printf)
3809 * @argptr: pointer to the first member of the variable argument list.
3811 * Write a formatted DTD internal entity.
3813 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3816 xmlTextWriterWriteVFormatDTDInternalEntity(xmlTextWriterPtr writer
,
3818 const xmlChar
* name
,
3828 buf
= xmlTextWriterVSprintf(format
, argptr
);
3832 rc
= xmlTextWriterWriteDTDInternalEntity(writer
, pe
, name
, buf
);
3839 * xmlTextWriterWriteDTDEntity:
3840 * @writer: the xmlTextWriterPtr
3841 * @pe: TRUE if this is a parameter entity, FALSE if not
3842 * @name: the name of the DTD entity
3843 * @pubid: the public identifier, which is an alternative to the system identifier
3844 * @sysid: the system identifier, which is the URI of the DTD
3845 * @ndataid: the xml notation name.
3846 * @content: content of the entity
3848 * Write a DTD entity.
3850 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3853 xmlTextWriterWriteDTDEntity(xmlTextWriterPtr writer
,
3855 const xmlChar
* name
,
3856 const xmlChar
* pubid
,
3857 const xmlChar
* sysid
,
3858 const xmlChar
* ndataid
,
3859 const xmlChar
* content
)
3861 if ((content
== NULL
) && (pubid
== NULL
) && (sysid
== NULL
))
3863 if ((pe
!= 0) && (ndataid
!= NULL
))
3866 if ((pubid
== NULL
) && (sysid
== NULL
))
3867 return xmlTextWriterWriteDTDInternalEntity(writer
, pe
, name
,
3870 return xmlTextWriterWriteDTDExternalEntity(writer
, pe
, name
, pubid
,
3875 * xmlTextWriterWriteDTDInternalEntity:
3876 * @writer: the xmlTextWriterPtr
3877 * @pe: TRUE if this is a parameter entity, FALSE if not
3878 * @name: the name of the DTD entity
3879 * @content: content of the entity
3881 * Write a DTD internal entity.
3883 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3886 xmlTextWriterWriteDTDInternalEntity(xmlTextWriterPtr writer
,
3888 const xmlChar
* name
,
3889 const xmlChar
* content
)
3894 if ((name
== NULL
) || (*name
== '\0') || (content
== NULL
))
3898 count
= xmlTextWriterStartDTDEntity(writer
, pe
, name
);
3903 count
= xmlTextWriterWriteString(writer
, content
);
3908 count
= xmlTextWriterEndDTDEntity(writer
);
3917 * xmlTextWriterWriteDTDExternalEntity:
3918 * @writer: the xmlTextWriterPtr
3919 * @pe: TRUE if this is a parameter entity, FALSE if not
3920 * @name: the name of the DTD entity
3921 * @pubid: the public identifier, which is an alternative to the system identifier
3922 * @sysid: the system identifier, which is the URI of the DTD
3923 * @ndataid: the xml notation name.
3925 * Write a DTD external entity. The entity must have been started with xmlTextWriterStartDTDEntity
3927 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3930 xmlTextWriterWriteDTDExternalEntity(xmlTextWriterPtr writer
,
3932 const xmlChar
* name
,
3933 const xmlChar
* pubid
,
3934 const xmlChar
* sysid
,
3935 const xmlChar
* ndataid
)
3940 if (((pubid
== NULL
) && (sysid
== NULL
)))
3942 if ((pe
!= 0) && (ndataid
!= NULL
))
3946 count
= xmlTextWriterStartDTDEntity(writer
, pe
, name
);
3952 xmlTextWriterWriteDTDExternalEntityContents(writer
, pubid
, sysid
,
3958 count
= xmlTextWriterEndDTDEntity(writer
);
3967 * xmlTextWriterWriteDTDExternalEntityContents:
3968 * @writer: the xmlTextWriterPtr
3969 * @pubid: the public identifier, which is an alternative to the system identifier
3970 * @sysid: the system identifier, which is the URI of the DTD
3971 * @ndataid: the xml notation name.
3973 * Write the contents of a DTD external entity.
3975 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
3978 xmlTextWriterWriteDTDExternalEntityContents(xmlTextWriterPtr writer
,
3979 const xmlChar
* pubid
,
3980 const xmlChar
* sysid
,
3981 const xmlChar
* ndataid
)
3986 xmlTextWriterStackEntry
*p
;
3988 if (writer
== NULL
) {
3989 xmlWriterErrMsg(writer
, XML_ERR_INTERNAL_ERROR
,
3990 "xmlTextWriterWriteDTDExternalEntityContents: xmlTextWriterPtr invalid!\n");
3995 lk
= xmlListFront(writer
->nodes
);
3997 xmlWriterErrMsg(writer
, XML_ERR_INTERNAL_ERROR
,
3998 "xmlTextWriterWriteDTDExternalEntityContents: you must call xmlTextWriterStartDTDEntity before the call to this function!\n");
4002 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
4007 case XML_TEXTWRITER_DTD_ENTY
:
4009 case XML_TEXTWRITER_DTD_PENT
:
4010 if (ndataid
!= NULL
) {
4011 xmlWriterErrMsg(writer
, XML_ERR_INTERNAL_ERROR
,
4012 "xmlTextWriterWriteDTDExternalEntityContents: notation not allowed with parameter entities!\n");
4017 xmlWriterErrMsg(writer
, XML_ERR_INTERNAL_ERROR
,
4018 "xmlTextWriterWriteDTDExternalEntityContents: you must call xmlTextWriterStartDTDEntity before the call to this function!\n");
4024 xmlWriterErrMsg(writer
, XML_ERR_INTERNAL_ERROR
,
4025 "xmlTextWriterWriteDTDExternalEntityContents: system identifier needed!\n");
4029 count
= xmlOutputBufferWriteString(writer
->out
, " PUBLIC ");
4034 count
= xmlOutputBufferWrite(writer
->out
, 1, &writer
->qchar
);
4040 xmlOutputBufferWriteString(writer
->out
, (const char *) pubid
);
4045 count
= xmlOutputBufferWrite(writer
->out
, 1, &writer
->qchar
);
4053 count
= xmlOutputBufferWriteString(writer
->out
, " SYSTEM");
4059 count
= xmlOutputBufferWriteString(writer
->out
, " ");
4064 count
= xmlOutputBufferWrite(writer
->out
, 1, &writer
->qchar
);
4070 xmlOutputBufferWriteString(writer
->out
, (const char *) sysid
);
4075 count
= xmlOutputBufferWrite(writer
->out
, 1, &writer
->qchar
);
4081 if (ndataid
!= NULL
) {
4082 count
= xmlOutputBufferWriteString(writer
->out
, " NDATA ");
4088 xmlOutputBufferWriteString(writer
->out
,
4089 (const char *) ndataid
);
4099 * xmlTextWriterWriteDTDNotation:
4100 * @writer: the xmlTextWriterPtr
4101 * @name: the name of the xml notation
4102 * @pubid: the public identifier, which is an alternative to the system identifier
4103 * @sysid: the system identifier, which is the URI of the DTD
4105 * Write a DTD entity.
4107 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
4110 xmlTextWriterWriteDTDNotation(xmlTextWriterPtr writer
,
4111 const xmlChar
* name
,
4112 const xmlChar
* pubid
, const xmlChar
* sysid
)
4117 xmlTextWriterStackEntry
*p
;
4119 if (writer
== NULL
|| name
== NULL
|| *name
== '\0')
4123 lk
= xmlListFront(writer
->nodes
);
4128 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
4131 case XML_TEXTWRITER_DTD
:
4132 count
= xmlOutputBufferWriteString(writer
->out
, " [");
4136 if (writer
->indent
) {
4137 count
= xmlOutputBufferWriteString(writer
->out
, "\n");
4142 p
->state
= XML_TEXTWRITER_DTD_TEXT
;
4144 case XML_TEXTWRITER_DTD_TEXT
:
4151 if (writer
->indent
) {
4152 count
= xmlTextWriterWriteIndent(writer
);
4158 count
= xmlOutputBufferWriteString(writer
->out
, "<!NOTATION ");
4162 count
= xmlOutputBufferWriteString(writer
->out
, (const char *) name
);
4168 count
= xmlOutputBufferWriteString(writer
->out
, " PUBLIC ");
4172 count
= xmlOutputBufferWrite(writer
->out
, 1, &writer
->qchar
);
4177 xmlOutputBufferWriteString(writer
->out
, (const char *) pubid
);
4181 count
= xmlOutputBufferWrite(writer
->out
, 1, &writer
->qchar
);
4189 count
= xmlOutputBufferWriteString(writer
->out
, " SYSTEM");
4194 count
= xmlOutputBufferWriteString(writer
->out
, " ");
4198 count
= xmlOutputBufferWrite(writer
->out
, 1, &writer
->qchar
);
4203 xmlOutputBufferWriteString(writer
->out
, (const char *) sysid
);
4207 count
= xmlOutputBufferWrite(writer
->out
, 1, &writer
->qchar
);
4213 count
= xmlOutputBufferWriteString(writer
->out
, ">");
4222 * xmlTextWriterFlush:
4223 * @writer: the xmlTextWriterPtr
4225 * Flush the output buffer.
4227 * Returns the bytes written (may be 0 because of buffering) or -1 in case of error
4230 xmlTextWriterFlush(xmlTextWriterPtr writer
)
4237 if (writer
->out
== NULL
)
4240 count
= xmlOutputBufferFlush(writer
->out
);
4250 * xmlFreeTextWriterStackEntry:
4251 * @lk: the xmlLinkPtr
4253 * Free callback for the xmlList.
4256 xmlFreeTextWriterStackEntry(xmlLinkPtr lk
)
4258 xmlTextWriterStackEntry
*p
;
4260 p
= (xmlTextWriterStackEntry
*) xmlLinkGetData(lk
);
4270 * xmlCmpTextWriterStackEntry:
4271 * @data0: the first data
4272 * @data1: the second data
4274 * Compare callback for the xmlList.
4279 xmlCmpTextWriterStackEntry(const void *data0
, const void *data1
)
4281 xmlTextWriterStackEntry
*p0
;
4282 xmlTextWriterStackEntry
*p1
;
4293 p0
= (xmlTextWriterStackEntry
*) data0
;
4294 p1
= (xmlTextWriterStackEntry
*) data1
;
4296 return xmlStrcmp(p0
->name
, p1
->name
);
4304 * xmlTextWriterOutputNSDecl:
4305 * @writer: the xmlTextWriterPtr
4307 * Output the current namespace declarations.
4310 xmlTextWriterOutputNSDecl(xmlTextWriterPtr writer
)
4313 xmlTextWriterNsStackEntry
*np
;
4318 while (!xmlListEmpty(writer
->nsstack
)) {
4319 xmlChar
*namespaceURI
= NULL
;
4320 xmlChar
*prefix
= NULL
;
4322 lk
= xmlListFront(writer
->nsstack
);
4323 np
= (xmlTextWriterNsStackEntry
*) xmlLinkGetData(lk
);
4326 namespaceURI
= xmlStrdup(np
->uri
);
4327 prefix
= xmlStrdup(np
->prefix
);
4330 xmlListPopFront(writer
->nsstack
);
4333 count
= xmlTextWriterWriteAttribute(writer
, prefix
, namespaceURI
);
4334 xmlFree(namespaceURI
);
4338 xmlListDelete(writer
->nsstack
);
4339 writer
->nsstack
= NULL
;
4349 * xmlFreeTextWriterNsStackEntry:
4350 * @lk: the xmlLinkPtr
4352 * Free callback for the xmlList.
4355 xmlFreeTextWriterNsStackEntry(xmlLinkPtr lk
)
4357 xmlTextWriterNsStackEntry
*p
;
4359 p
= (xmlTextWriterNsStackEntry
*) xmlLinkGetData(lk
);
4372 * xmlCmpTextWriterNsStackEntry:
4373 * @data0: the first data
4374 * @data1: the second data
4376 * Compare callback for the xmlList.
4381 xmlCmpTextWriterNsStackEntry(const void *data0
, const void *data1
)
4383 xmlTextWriterNsStackEntry
*p0
;
4384 xmlTextWriterNsStackEntry
*p1
;
4396 p0
= (xmlTextWriterNsStackEntry
*) data0
;
4397 p1
= (xmlTextWriterNsStackEntry
*) data1
;
4399 rc
= xmlStrcmp(p0
->prefix
, p1
->prefix
);
4401 if ((rc
!= 0) || (p0
->elem
!= p1
->elem
))
4408 * xmlTextWriterWriteDocCallback:
4409 * @context: the xmlBufferPtr
4410 * @str: the data to write
4411 * @len: the length of the data
4413 * Write callback for the xmlOutputBuffer with target xmlBuffer
4418 xmlTextWriterWriteDocCallback(void *context
, const xmlChar
* str
, int len
)
4420 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) context
;
4423 if ((rc
= xmlParseChunk(ctxt
, (const char *) str
, len
, 0)) != 0) {
4424 xmlWriterErrMsgInt(NULL
, XML_ERR_INTERNAL_ERROR
,
4425 "xmlTextWriterWriteDocCallback : XML error %d !\n",
4434 * xmlTextWriterCloseDocCallback:
4435 * @context: the xmlBufferPtr
4437 * Close callback for the xmlOutputBuffer with target xmlBuffer
4442 xmlTextWriterCloseDocCallback(void *context
)
4444 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) context
;
4447 if ((rc
= xmlParseChunk(ctxt
, NULL
, 0, 1)) != 0) {
4448 xmlWriterErrMsgInt(NULL
, XML_ERR_INTERNAL_ERROR
,
4449 "xmlTextWriterWriteDocCallback : XML error %d !\n",
4458 * xmlTextWriterVSprintf:
4459 * @format: see printf
4460 * @argptr: pointer to the first member of the variable argument list.
4462 * Utility function for formatted output
4464 * Returns a new xmlChar buffer with the data or NULL on error. This buffer must be freed.
4467 xmlTextWriterVSprintf(const char *format
, va_list argptr
)
4475 buf
= (xmlChar
*) xmlMalloc(size
);
4477 xmlWriterErrMsg(NULL
, XML_ERR_NO_MEMORY
,
4478 "xmlTextWriterVSprintf : out of memory!\n");
4482 VA_COPY(locarg
, argptr
);
4483 while (((count
= vsnprintf((char *) buf
, size
, format
, locarg
)) < 0)
4484 || (count
== size
- 1) || (count
== size
) || (count
> size
)) {
4488 buf
= (xmlChar
*) xmlMalloc(size
);
4490 xmlWriterErrMsg(NULL
, XML_ERR_NO_MEMORY
,
4491 "xmlTextWriterVSprintf : out of memory!\n");
4494 VA_COPY(locarg
, argptr
);
4502 * xmlTextWriterStartDocumentCallback:
4503 * @ctx: the user data (XML parser context)
4505 * called at the start of document processing.
4508 xmlTextWriterStartDocumentCallback(void *ctx
)
4510 xmlParserCtxtPtr ctxt
= (xmlParserCtxtPtr
) ctx
;
4514 #ifdef LIBXML_HTML_ENABLED
4515 if (ctxt
->myDoc
== NULL
)
4516 ctxt
->myDoc
= htmlNewDocNoDtD(NULL
, NULL
);
4517 if (ctxt
->myDoc
== NULL
) {
4518 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
4519 ctxt
->sax
->error(ctxt
->userData
,
4520 "SAX.startDocument(): out of memory\n");
4521 ctxt
->errNo
= XML_ERR_NO_MEMORY
;
4522 ctxt
->instate
= XML_PARSER_EOF
;
4523 ctxt
->disableSAX
= 1;
4527 xmlWriterErrMsg(NULL
, XML_ERR_INTERNAL_ERROR
,
4528 "libxml2 built without HTML support\n");
4529 ctxt
->errNo
= XML_ERR_INTERNAL_ERROR
;
4530 ctxt
->instate
= XML_PARSER_EOF
;
4531 ctxt
->disableSAX
= 1;
4537 doc
= ctxt
->myDoc
= xmlNewDoc(ctxt
->version
);
4539 if (doc
->children
== NULL
) {
4540 if (ctxt
->encoding
!= NULL
)
4541 doc
->encoding
= xmlStrdup(ctxt
->encoding
);
4543 doc
->encoding
= NULL
;
4544 doc
->standalone
= ctxt
->standalone
;
4547 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
4548 ctxt
->sax
->error(ctxt
->userData
,
4549 "SAX.startDocument(): out of memory\n");
4550 ctxt
->errNo
= XML_ERR_NO_MEMORY
;
4551 ctxt
->instate
= XML_PARSER_EOF
;
4552 ctxt
->disableSAX
= 1;
4556 if ((ctxt
->myDoc
!= NULL
) && (ctxt
->myDoc
->URL
== NULL
) &&
4557 (ctxt
->input
!= NULL
) && (ctxt
->input
->filename
!= NULL
)) {
4559 xmlCanonicPath((const xmlChar
*) ctxt
->input
->filename
);
4560 if (ctxt
->myDoc
->URL
== NULL
)
4562 xmlStrdup((const xmlChar
*) ctxt
->input
->filename
);
4567 * xmlTextWriterSetIndent:
4568 * @writer: the xmlTextWriterPtr
4569 * @indent: do indentation?
4571 * Set indentation output. indent = 0 do not indentation. indent > 0 do indentation.
4573 * Returns -1 on error or 0 otherwise.
4576 xmlTextWriterSetIndent(xmlTextWriterPtr writer
, int indent
)
4578 if ((writer
== NULL
) || (indent
< 0))
4581 writer
->indent
= indent
;
4582 writer
->doindent
= 1;
4588 * xmlTextWriterSetIndentString:
4589 * @writer: the xmlTextWriterPtr
4590 * @str: the xmlChar string
4592 * Set string indentation.
4594 * Returns -1 on error or 0 otherwise.
4597 xmlTextWriterSetIndentString(xmlTextWriterPtr writer
, const xmlChar
* str
)
4599 if ((writer
== NULL
) || (!str
))
4602 if (writer
->ichar
!= NULL
)
4603 xmlFree(writer
->ichar
);
4604 writer
->ichar
= xmlStrdup(str
);
4613 * xmlTextWriterSetQuoteChar:
4614 * @writer: the xmlTextWriterPtr
4615 * @quotechar: the quote character
4617 * Set the character used for quoting attributes.
4619 * Returns -1 on error or 0 otherwise.
4622 xmlTextWriterSetQuoteChar(xmlTextWriterPtr writer
, xmlChar quotechar
)
4624 if ((writer
== NULL
) || ((quotechar
!= '\'') && (quotechar
!= '"')))
4627 writer
->qchar
= quotechar
;
4633 * xmlTextWriterWriteIndent:
4634 * @writer: the xmlTextWriterPtr
4636 * Write indent string.
4638 * Returns -1 on error or the number of strings written.
4641 xmlTextWriterWriteIndent(xmlTextWriterPtr writer
)
4647 lksize
= xmlListSize(writer
->nodes
);
4649 return (-1); /* list is empty */
4650 for (i
= 0; i
< (lksize
- 1); i
++) {
4651 ret
= xmlOutputBufferWriteString(writer
->out
,
4652 (const char *) writer
->ichar
);
4657 return (lksize
- 1);
4661 * xmlTextWriterHandleStateDependencies:
4662 * @writer: the xmlTextWriterPtr
4663 * @p: the xmlTextWriterStackEntry
4665 * Write state dependent strings.
4667 * Returns -1 on error or the number of characters written.
4670 xmlTextWriterHandleStateDependencies(xmlTextWriterPtr writer
,
4671 xmlTextWriterStackEntry
* p
)
4684 extra
[0] = extra
[1] = extra
[2] = '\0';
4688 case XML_TEXTWRITER_NAME
:
4689 /* Output namespace declarations */
4690 count
= xmlTextWriterOutputNSDecl(writer
);
4695 p
->state
= XML_TEXTWRITER_TEXT
;
4697 case XML_TEXTWRITER_PI
:
4699 p
->state
= XML_TEXTWRITER_PI_TEXT
;
4701 case XML_TEXTWRITER_DTD
:
4704 p
->state
= XML_TEXTWRITER_DTD_TEXT
;
4706 case XML_TEXTWRITER_DTD_ELEM
:
4708 p
->state
= XML_TEXTWRITER_DTD_ELEM_TEXT
;
4710 case XML_TEXTWRITER_DTD_ATTL
:
4712 p
->state
= XML_TEXTWRITER_DTD_ATTL_TEXT
;
4714 case XML_TEXTWRITER_DTD_ENTY
:
4715 case XML_TEXTWRITER_DTD_PENT
:
4717 extra
[1] = writer
->qchar
;
4718 p
->state
= XML_TEXTWRITER_DTD_ENTY_TEXT
;
4725 if (*extra
!= '\0') {
4726 count
= xmlOutputBufferWriteString(writer
->out
, extra
);
4735 #define bottom_xmlwriter
4736 #include "elfgcchack.h"