2003-11-20 14:59:09 +03:00
2003-10-21 02:32:39 +04:00
/*
* xmlwriter . c : XML text writer implementation
*
* For license and disclaimer see the license and disclaimer of
* libxml2 .
*
* alfred @ mickautsch . de
*/
2003-11-27 21:36:46 +03:00
# define IN_LIBXML
2007-01-31 21:38:56 +03:00
# include "libxml.h"
2003-10-21 02:32:39 +04:00
# include <string.h>
# include <libxml/xmlmemory.h>
# include <libxml/parser.h>
2003-11-20 14:59:09 +03:00
# include <libxml/uri.h>
# include <libxml/HTMLtree.h>
2003-10-21 02:32:39 +04:00
# ifdef LIBXML_WRITER_ENABLED
# include <libxml/xmlwriter.h>
2012-07-16 10:54:45 +04:00
# include "buf.h"
# include "enc.h"
# include "save.h"
2003-10-21 02:32:39 +04:00
# define B64LINELEN 72
# define B64CRLF "\r\n"
2005-10-20 13:04:05 +04:00
/*
* The following VA_COPY was coded following an example in
* the Samba project . It may not be sufficient for some
2013-12-12 11:04:43 +04:00
* esoteric implementations of va_list but ( hopefully ) will
* be sufficient for libxml2 .
2005-10-20 13:04:05 +04:00
*/
# ifndef VA_COPY
# ifdef HAVE_VA_COPY
# define VA_COPY(dest, src) va_copy(dest, src)
# else
# ifdef HAVE___VA_COPY
# define VA_COPY(dest,src) __va_copy(dest, src)
# else
2013-12-12 11:04:43 +04:00
# ifndef VA_LIST_IS_ARRAY
# define VA_COPY(dest,src) (dest) = (src)
# else
# include <string.h>
# define VA_COPY(dest,src) memcpy((char *)(dest),(char *)(src),sizeof(va_list))
# endif
2005-10-20 13:04:05 +04:00
# endif
# endif
# endif
2003-10-21 02:32:39 +04:00
/*
* Types are kept private
*/
typedef enum {
XML_TEXTWRITER_NONE = 0 ,
XML_TEXTWRITER_NAME ,
XML_TEXTWRITER_ATTRIBUTE ,
XML_TEXTWRITER_TEXT ,
XML_TEXTWRITER_PI ,
XML_TEXTWRITER_PI_TEXT ,
XML_TEXTWRITER_CDATA ,
XML_TEXTWRITER_DTD ,
XML_TEXTWRITER_DTD_TEXT ,
XML_TEXTWRITER_DTD_ELEM ,
2004-03-22 18:22:58 +03:00
XML_TEXTWRITER_DTD_ELEM_TEXT ,
2003-10-21 02:32:39 +04:00
XML_TEXTWRITER_DTD_ATTL ,
2004-03-22 18:22:58 +03:00
XML_TEXTWRITER_DTD_ATTL_TEXT ,
XML_TEXTWRITER_DTD_ENTY , /* entity */
XML_TEXTWRITER_DTD_ENTY_TEXT ,
XML_TEXTWRITER_DTD_PENT , /* parameter entity */
2004-04-17 18:58:15 +04:00
XML_TEXTWRITER_COMMENT
2003-10-21 02:32:39 +04:00
} xmlTextWriterState ;
typedef struct _xmlTextWriterStackEntry xmlTextWriterStackEntry ;
struct _xmlTextWriterStackEntry {
xmlChar * name ;
xmlTextWriterState state ;
} ;
typedef struct _xmlTextWriterNsStackEntry xmlTextWriterNsStackEntry ;
struct _xmlTextWriterNsStackEntry {
xmlChar * prefix ;
xmlChar * uri ;
xmlLinkPtr elem ;
} ;
struct _xmlTextWriter {
2004-02-17 14:40:32 +03:00
xmlOutputBufferPtr out ; /* output buffer */
xmlListPtr nodes ; /* element name stack */
xmlListPtr nsstack ; /* name spaces stack */
2003-10-21 02:32:39 +04:00
int level ;
2004-02-17 14:40:32 +03:00
int indent ; /* enable indent */
int doindent ; /* internal indent flag */
xmlChar * ichar ; /* indent character */
char qchar ; /* character used for quoting attribute values */
2004-01-21 12:57:31 +03:00
xmlParserCtxtPtr ctxt ;
2004-11-09 17:59:59 +03:00
int no_doc_free ;
2006-08-17 02:48:51 +04:00
xmlDocPtr doc ;
2003-10-21 02:32:39 +04:00
} ;
static void xmlFreeTextWriterStackEntry ( xmlLinkPtr lk ) ;
static int xmlCmpTextWriterStackEntry ( const void * data0 ,
const void * data1 ) ;
2007-06-08 12:50:47 +04:00
static int xmlTextWriterOutputNSDecl ( xmlTextWriterPtr writer ) ;
2003-10-21 02:32:39 +04:00
static void xmlFreeTextWriterNsStackEntry ( xmlLinkPtr lk ) ;
static int xmlCmpTextWriterNsStackEntry ( const void * data0 ,
const void * data1 ) ;
2003-11-20 14:59:09 +03:00
static int xmlTextWriterWriteDocCallback ( void * context ,
2017-11-09 19:47:47 +03:00
const char * str , int len ) ;
2003-11-20 14:59:09 +03:00
static int xmlTextWriterCloseDocCallback ( void * context ) ;
2016-05-13 10:13:17 +03:00
static xmlChar * xmlTextWriterVSprintf ( const char * format , va_list argptr ) LIBXML_ATTR_FORMAT ( 1 , 0 ) ;
2003-10-21 02:32:39 +04:00
static int xmlOutputBufferWriteBase64 ( xmlOutputBufferPtr out , int len ,
const unsigned char * data ) ;
2003-11-20 14:59:09 +03:00
static void xmlTextWriterStartDocumentCallback ( void * ctx ) ;
2004-02-17 14:40:32 +03:00
static int xmlTextWriterWriteIndent ( xmlTextWriterPtr writer ) ;
2004-03-22 18:22:58 +03:00
static int
xmlTextWriterHandleStateDependencies ( xmlTextWriterPtr writer ,
xmlTextWriterStackEntry * p ) ;
2003-10-21 02:32:39 +04:00
2004-11-03 17:20:29 +03:00
/**
* xmlWriterErrMsg :
* @ ctxt : a writer context
* @ error : the error number
* @ msg : the error message
*
* Handle a writer error
*/
static void
xmlWriterErrMsg ( xmlTextWriterPtr ctxt , xmlParserErrors error ,
const char * msg )
{
if ( ctxt ! = NULL ) {
__xmlRaiseError ( NULL , NULL , NULL , ctxt - > ctxt ,
NULL , XML_FROM_WRITER , error , XML_ERR_FATAL ,
2009-06-04 13:22:45 +04:00
NULL , 0 , NULL , NULL , NULL , 0 , 0 , " %s " , msg ) ;
2004-11-03 17:20:29 +03:00
} else {
__xmlRaiseError ( NULL , NULL , NULL , NULL , NULL , XML_FROM_WRITER , error ,
2009-06-04 13:22:45 +04:00
XML_ERR_FATAL , NULL , 0 , NULL , NULL , NULL , 0 , 0 , " %s " , msg ) ;
2004-11-03 17:20:29 +03:00
}
}
/**
* xmlWriterErrMsgInt :
* @ ctxt : a writer context
* @ error : the error number
* @ msg : the error message
* @ val : an int
*
* Handle a writer error
*/
2016-05-13 10:13:17 +03:00
static void LIBXML_ATTR_FORMAT ( 3 , 0 )
2004-11-03 17:20:29 +03:00
xmlWriterErrMsgInt ( xmlTextWriterPtr ctxt , xmlParserErrors error ,
const char * msg , int val )
{
if ( ctxt ! = NULL ) {
__xmlRaiseError ( NULL , NULL , NULL , ctxt - > ctxt ,
NULL , XML_FROM_WRITER , error , XML_ERR_FATAL ,
NULL , 0 , NULL , NULL , NULL , val , 0 , msg , val ) ;
} else {
__xmlRaiseError ( NULL , NULL , NULL , NULL , NULL , XML_FROM_WRITER , error ,
XML_ERR_FATAL , NULL , 0 , NULL , NULL , NULL , val , 0 , msg , val ) ;
}
}
2003-10-21 02:32:39 +04:00
/**
* xmlNewTextWriter :
* @ out : an xmlOutputBufferPtr
*
* Create a new xmlNewTextWriter structure using an xmlOutputBufferPtr
2004-11-06 22:24:28 +03:00
* NOTE : the @ out parameter will be deallocated when the writer is closed
* ( if the call succeed . )
2003-10-21 02:32:39 +04:00
*
* Returns the new xmlTextWriterPtr or NULL in case of error
*/
xmlTextWriterPtr
xmlNewTextWriter ( xmlOutputBufferPtr out )
{
xmlTextWriterPtr ret ;
ret = ( xmlTextWriterPtr ) xmlMalloc ( sizeof ( xmlTextWriter ) ) ;
if ( ret = = NULL ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( NULL , XML_ERR_NO_MEMORY ,
2003-10-21 02:32:39 +04:00
" xmlNewTextWriter : out of memory! \n " ) ;
return NULL ;
}
memset ( ret , 0 , ( size_t ) sizeof ( xmlTextWriter ) ) ;
2017-11-09 19:28:00 +03:00
ret - > nodes = xmlListCreate ( xmlFreeTextWriterStackEntry ,
2003-10-21 02:32:39 +04:00
xmlCmpTextWriterStackEntry ) ;
if ( ret - > nodes = = NULL ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( NULL , XML_ERR_NO_MEMORY ,
2003-10-21 02:32:39 +04:00
" xmlNewTextWriter : out of memory! \n " ) ;
xmlFree ( ret ) ;
return NULL ;
}
2017-11-09 19:28:00 +03:00
ret - > nsstack = xmlListCreate ( xmlFreeTextWriterNsStackEntry ,
2003-10-21 02:32:39 +04:00
xmlCmpTextWriterNsStackEntry ) ;
if ( ret - > nsstack = = NULL ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( NULL , XML_ERR_NO_MEMORY ,
2003-10-21 02:32:39 +04:00
" xmlNewTextWriter : out of memory! \n " ) ;
2004-03-22 18:22:58 +03:00
xmlListDelete ( ret - > nodes ) ;
2003-10-21 02:32:39 +04:00
xmlFree ( ret ) ;
return NULL ;
}
ret - > out = out ;
2004-02-17 14:40:32 +03:00
ret - > ichar = xmlStrdup ( BAD_CAST " " ) ;
2003-10-21 02:32:39 +04:00
ret - > qchar = ' " ' ;
2004-03-22 18:22:58 +03:00
if ( ! ret - > ichar ) {
xmlListDelete ( ret - > nodes ) ;
xmlListDelete ( ret - > nsstack ) ;
xmlFree ( ret ) ;
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( NULL , XML_ERR_NO_MEMORY ,
2004-03-22 18:22:58 +03:00
" xmlNewTextWriter : out of memory! \n " ) ;
2004-02-17 14:40:32 +03:00
return NULL ;
2004-03-22 18:22:58 +03:00
}
2006-08-17 02:48:51 +04:00
ret - > doc = xmlNewDoc ( NULL ) ;
2004-11-09 17:59:59 +03:00
ret - > no_doc_free = 0 ;
2004-02-17 14:40:32 +03:00
2003-10-21 02:32:39 +04:00
return ret ;
}
/**
* xmlNewTextWriterFilename :
* @ uri : the URI of the resource for the output
* @ compression : compress the output ?
*
* Create a new xmlNewTextWriter structure with @ uri as output
*
* Returns the new xmlTextWriterPtr or NULL in case of error
*/
xmlTextWriterPtr
xmlNewTextWriterFilename ( const char * uri , int compression )
{
xmlTextWriterPtr ret ;
xmlOutputBufferPtr out ;
out = xmlOutputBufferCreateFilename ( uri , NULL , compression ) ;
if ( out = = NULL ) {
2009-06-19 21:54:25 +04:00
xmlWriterErrMsg ( NULL , XML_IO_EIO ,
" xmlNewTextWriterFilename : cannot open uri \n " ) ;
2003-10-21 02:32:39 +04:00
return NULL ;
}
ret = xmlNewTextWriter ( out ) ;
if ( ret = = NULL ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( NULL , XML_ERR_NO_MEMORY ,
2003-10-21 02:32:39 +04:00
" xmlNewTextWriterFilename : out of memory! \n " ) ;
xmlOutputBufferClose ( out ) ;
return NULL ;
}
2004-01-02 23:04:23 +03:00
ret - > indent = 0 ;
ret - > doindent = 0 ;
2003-10-21 02:32:39 +04:00
return ret ;
}
/**
* xmlNewTextWriterMemory :
* @ buf : xmlBufferPtr
* @ compression : compress the output ?
*
* Create a new xmlNewTextWriter structure with @ buf as output
* TODO : handle compression
*
* Returns the new xmlTextWriterPtr or NULL in case of error
*/
xmlTextWriterPtr
xmlNewTextWriterMemory ( xmlBufferPtr buf , int compression ATTRIBUTE_UNUSED )
{
xmlTextWriterPtr ret ;
xmlOutputBufferPtr out ;
/*::todo handle compression */
2005-11-09 21:03:45 +03:00
out = xmlOutputBufferCreateBuffer ( buf , NULL ) ;
2003-10-21 02:32:39 +04:00
if ( out = = NULL ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( NULL , XML_ERR_NO_MEMORY ,
2003-10-21 02:32:39 +04:00
" xmlNewTextWriterMemory : out of memory! \n " ) ;
return NULL ;
}
ret = xmlNewTextWriter ( out ) ;
if ( ret = = NULL ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( NULL , XML_ERR_NO_MEMORY ,
2003-10-21 02:32:39 +04:00
" xmlNewTextWriterMemory : out of memory! \n " ) ;
xmlOutputBufferClose ( out ) ;
return NULL ;
}
return ret ;
}
2003-11-20 14:59:09 +03:00
/**
* xmlNewTextWriterPushParser :
* @ ctxt : xmlParserCtxtPtr to hold the new XML document tree
* @ compression : compress the output ?
*
* Create a new xmlNewTextWriter structure with @ ctxt as output
2004-11-06 22:24:28 +03:00
* NOTE : the @ ctxt context will be freed with the resulting writer
* ( if the call succeeds ) .
2003-11-20 14:59:09 +03:00
* TODO : handle compression
*
* Returns the new xmlTextWriterPtr or NULL in case of error
*/
xmlTextWriterPtr
2003-11-21 03:28:39 +03:00
xmlNewTextWriterPushParser ( xmlParserCtxtPtr ctxt ,
int compression ATTRIBUTE_UNUSED )
2003-11-20 14:59:09 +03:00
{
xmlTextWriterPtr ret ;
xmlOutputBufferPtr out ;
2004-03-22 18:22:58 +03:00
if ( ctxt = = NULL ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( NULL , XML_ERR_INTERNAL_ERROR ,
2004-03-22 18:22:58 +03:00
" xmlNewTextWriterPushParser : invalid context! \n " ) ;
return NULL ;
}
2017-11-09 19:47:47 +03:00
out = xmlOutputBufferCreateIO ( xmlTextWriterWriteDocCallback ,
2003-11-20 14:59:09 +03:00
xmlTextWriterCloseDocCallback ,
( void * ) ctxt , NULL ) ;
if ( out = = NULL ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( NULL , XML_ERR_INTERNAL_ERROR ,
2003-11-20 14:59:09 +03:00
" xmlNewTextWriterPushParser : error at xmlOutputBufferCreateIO! \n " ) ;
return NULL ;
}
ret = xmlNewTextWriter ( out ) ;
if ( ret = = NULL ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( NULL , XML_ERR_INTERNAL_ERROR ,
2003-11-20 14:59:09 +03:00
" xmlNewTextWriterPushParser : error at xmlNewTextWriter! \n " ) ;
xmlOutputBufferClose ( out ) ;
return NULL ;
}
2004-01-21 12:57:31 +03:00
ret - > ctxt = ctxt ;
2003-11-20 14:59:09 +03:00
return ret ;
}
/**
* xmlNewTextWriterDoc :
* @ doc : address of a xmlDocPtr to hold the new XML document tree
* @ compression : compress the output ?
*
* Create a new xmlNewTextWriter structure with @ * doc as output
*
* Returns the new xmlTextWriterPtr or NULL in case of error
*/
xmlTextWriterPtr
xmlNewTextWriterDoc ( xmlDocPtr * doc , int compression )
{
xmlTextWriterPtr ret ;
xmlSAXHandler saxHandler ;
xmlParserCtxtPtr ctxt ;
memset ( & saxHandler , ' \0 ' , sizeof ( saxHandler ) ) ;
xmlSAX2InitDefaultSAXHandler ( & saxHandler , 1 ) ;
saxHandler . startDocument = xmlTextWriterStartDocumentCallback ;
saxHandler . startElement = xmlSAX2StartElement ;
saxHandler . endElement = xmlSAX2EndElement ;
ctxt = xmlCreatePushParserCtxt ( & saxHandler , NULL , NULL , 0 , NULL ) ;
if ( ctxt = = NULL ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( NULL , XML_ERR_INTERNAL_ERROR ,
2009-02-20 11:19:53 +03:00
" xmlNewTextWriterDoc : error at xmlCreatePushParserCtxt! \n " ) ;
2003-11-20 14:59:09 +03:00
return NULL ;
}
2004-10-26 20:06:51 +04:00
/*
* For some reason this seems to completely break if node names
* are interned .
*/
ctxt - > dictNames = 0 ;
2003-11-20 14:59:09 +03:00
2003-11-21 03:28:39 +03:00
ctxt - > myDoc = xmlNewDoc ( BAD_CAST XML_DEFAULT_VERSION ) ;
2003-11-20 14:59:09 +03:00
if ( ctxt - > myDoc = = NULL ) {
xmlFreeParserCtxt ( ctxt ) ;
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( NULL , XML_ERR_INTERNAL_ERROR ,
2003-11-20 14:59:09 +03:00
" xmlNewTextWriterDoc : error at xmlNewDoc! \n " ) ;
return NULL ;
}
ret = xmlNewTextWriterPushParser ( ctxt , compression ) ;
if ( ret = = NULL ) {
2009-02-20 11:19:53 +03:00
xmlFreeDoc ( ctxt - > myDoc ) ;
xmlFreeParserCtxt ( ctxt ) ;
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( NULL , XML_ERR_INTERNAL_ERROR ,
2009-02-20 11:19:53 +03:00
" xmlNewTextWriterDoc : error at xmlNewTextWriterPushParser! \n " ) ;
2003-11-20 14:59:09 +03:00
return NULL ;
}
2004-03-22 18:22:58 +03:00
xmlSetDocCompressMode ( ctxt - > myDoc , compression ) ;
2004-11-09 17:59:59 +03:00
if ( doc ! = NULL ) {
2004-03-22 18:22:58 +03:00
* doc = ctxt - > myDoc ;
2004-11-09 17:59:59 +03:00
ret - > no_doc_free = 1 ;
}
2003-11-20 14:59:09 +03:00
return ret ;
}
/**
* xmlNewTextWriterTree :
* @ doc : xmlDocPtr
* @ node : xmlNodePtr or NULL for doc - > children
* @ compression : compress the output ?
*
* Create a new xmlNewTextWriter structure with @ doc as output
* starting at @ node
*
* Returns the new xmlTextWriterPtr or NULL in case of error
*/
xmlTextWriterPtr
xmlNewTextWriterTree ( xmlDocPtr doc , xmlNodePtr node , int compression )
{
xmlTextWriterPtr ret ;
xmlSAXHandler saxHandler ;
xmlParserCtxtPtr ctxt ;
if ( doc = = NULL ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( NULL , XML_ERR_INTERNAL_ERROR ,
2004-03-22 18:22:58 +03:00
" xmlNewTextWriterTree : invalid document tree! \n " ) ;
2003-11-20 14:59:09 +03:00
return NULL ;
}
memset ( & saxHandler , ' \0 ' , sizeof ( saxHandler ) ) ;
xmlSAX2InitDefaultSAXHandler ( & saxHandler , 1 ) ;
saxHandler . startDocument = xmlTextWriterStartDocumentCallback ;
saxHandler . startElement = xmlSAX2StartElement ;
saxHandler . endElement = xmlSAX2EndElement ;
ctxt = xmlCreatePushParserCtxt ( & saxHandler , NULL , NULL , 0 , NULL ) ;
if ( ctxt = = NULL ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( NULL , XML_ERR_INTERNAL_ERROR ,
2003-11-20 14:59:09 +03:00
" xmlNewTextWriterDoc : error at xmlCreatePushParserCtxt! \n " ) ;
return NULL ;
}
2004-10-26 20:06:51 +04:00
/*
* For some reason this seems to completely break if node names
* are interned .
*/
ctxt - > dictNames = 0 ;
2003-11-20 14:59:09 +03:00
ret = xmlNewTextWriterPushParser ( ctxt , compression ) ;
if ( ret = = NULL ) {
2004-03-22 18:22:58 +03:00
xmlFreeParserCtxt ( ctxt ) ;
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( NULL , XML_ERR_INTERNAL_ERROR ,
2003-11-20 14:59:09 +03:00
" xmlNewTextWriterDoc : error at xmlNewTextWriterPushParser! \n " ) ;
return NULL ;
}
2004-03-22 18:22:58 +03:00
ctxt - > myDoc = doc ;
ctxt - > node = node ;
2004-11-09 17:59:59 +03:00
ret - > no_doc_free = 1 ;
2004-03-22 18:22:58 +03:00
2003-11-20 14:59:09 +03:00
xmlSetDocCompressMode ( doc , compression ) ;
return ret ;
}
2003-10-21 02:32:39 +04:00
/**
* xmlFreeTextWriter :
* @ writer : the xmlTextWriterPtr
*
* Deallocate all the resources associated to the writer
*/
void
xmlFreeTextWriter ( xmlTextWriterPtr writer )
{
if ( writer = = NULL )
return ;
if ( writer - > out ! = NULL )
xmlOutputBufferClose ( writer - > out ) ;
if ( writer - > nodes ! = NULL )
xmlListDelete ( writer - > nodes ) ;
if ( writer - > nsstack ! = NULL )
xmlListDelete ( writer - > nsstack ) ;
2004-11-09 17:59:59 +03:00
if ( writer - > ctxt ! = NULL ) {
if ( ( writer - > ctxt - > myDoc ! = NULL ) & & ( writer - > no_doc_free = = 0 ) ) {
xmlFreeDoc ( writer - > ctxt - > myDoc ) ;
writer - > ctxt - > myDoc = NULL ;
}
2004-01-21 12:57:31 +03:00
xmlFreeParserCtxt ( writer - > ctxt ) ;
2004-11-09 17:59:59 +03:00
}
2004-01-21 12:57:31 +03:00
2006-08-17 02:48:51 +04:00
if ( writer - > doc ! = NULL )
xmlFreeDoc ( writer - > doc ) ;
2004-01-23 16:15:13 +03:00
if ( writer - > ichar ! = NULL )
xmlFree ( writer - > ichar ) ;
2003-10-21 02:32:39 +04:00
xmlFree ( writer ) ;
}
/**
* xmlTextWriterStartDocument :
* @ writer : the xmlTextWriterPtr
* @ version : the xml version ( " 1.0 " ) or NULL for default ( " 1.0 " )
* @ encoding : the encoding or NULL for default
* @ standalone : " yes " or " no " or NULL for default
*
* Start a new xml document
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterStartDocument ( xmlTextWriterPtr writer , const char * version ,
const char * encoding , const char * standalone )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlCharEncodingHandlerPtr encoder ;
2004-03-22 18:22:58 +03:00
if ( ( writer = = NULL ) | | ( writer - > out = = NULL ) ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_INTERNAL_ERROR ,
2004-03-22 18:22:58 +03:00
" xmlTextWriterStartDocument : invalid writer! \n " ) ;
2003-10-21 02:32:39 +04:00
return - 1 ;
2004-03-22 18:22:58 +03:00
}
2003-10-21 02:32:39 +04:00
lk = xmlListFront ( writer - > nodes ) ;
if ( ( lk ! = NULL ) & & ( xmlLinkGetData ( lk ) ! = NULL ) ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_INTERNAL_ERROR ,
2004-03-22 18:22:58 +03:00
" xmlTextWriterStartDocument : not allowed in this context! \n " ) ;
2003-10-21 02:32:39 +04:00
return - 1 ;
}
encoder = NULL ;
if ( encoding ! = NULL ) {
encoder = xmlFindCharEncodingHandler ( encoding ) ;
if ( encoder = = NULL ) {
2019-10-14 18:04:04 +03:00
xmlWriterErrMsg ( writer , XML_ERR_UNSUPPORTED_ENCODING ,
" xmlTextWriterStartDocument : unsupported encoding \n " ) ;
2003-10-21 02:32:39 +04:00
return - 1 ;
}
}
writer - > out - > encoder = encoder ;
if ( encoder ! = NULL ) {
2007-07-04 19:42:46 +04:00
if ( writer - > out - > conv = = NULL ) {
2012-07-16 10:54:45 +04:00
writer - > out - > conv = xmlBufCreateSize ( 4000 ) ;
2007-07-04 19:42:46 +04:00
}
2012-07-16 10:54:45 +04:00
xmlCharEncOutput ( writer - > out , 1 ) ;
2006-08-17 02:48:51 +04:00
if ( ( writer - > doc ! = NULL ) & & ( writer - > doc - > encoding = = NULL ) )
writer - > doc - > encoding = xmlStrdup ( ( xmlChar * ) writer - > out - > encoder - > name ) ;
2003-10-21 02:32:39 +04:00
} else
writer - > out - > conv = NULL ;
sum = 0 ;
count = xmlOutputBufferWriteString ( writer - > out , " <?xml version= " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWrite ( writer - > out , 1 , & writer - > qchar ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
if ( version ! = 0 )
count = xmlOutputBufferWriteString ( writer - > out , version ) ;
else
count = xmlOutputBufferWriteString ( writer - > out , " 1.0 " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWrite ( writer - > out , 1 , & writer - > qchar ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
if ( writer - > out - > encoder ! = 0 ) {
count = xmlOutputBufferWriteString ( writer - > out , " encoding= " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWrite ( writer - > out , 1 , & writer - > qchar ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count =
xmlOutputBufferWriteString ( writer - > out ,
writer - > out - > encoder - > name ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWrite ( writer - > out , 1 , & writer - > qchar ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
}
if ( standalone ! = 0 ) {
count = xmlOutputBufferWriteString ( writer - > out , " standalone= " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWrite ( writer - > out , 1 , & writer - > qchar ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWriteString ( writer - > out , standalone ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWrite ( writer - > out , 1 , & writer - > qchar ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
}
count = xmlOutputBufferWriteString ( writer - > out , " ?> \n " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
return sum ;
}
/**
* xmlTextWriterEndDocument :
* @ writer : the xmlTextWriterPtr
*
2008-02-13 13:17:41 +03:00
* End an xml document . All open elements are closed , and
* the content is flushed to the output .
2003-10-21 02:32:39 +04:00
*
2008-02-13 13:17:41 +03:00
* Returns the bytes written or - 1 in case of error
2003-10-21 02:32:39 +04:00
*/
int
xmlTextWriterEndDocument ( xmlTextWriterPtr writer )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
2004-03-22 18:22:58 +03:00
if ( writer = = NULL ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_INTERNAL_ERROR ,
2004-03-22 18:22:58 +03:00
" xmlTextWriterEndDocument : invalid writer! \n " ) ;
2003-10-21 02:32:39 +04:00
return - 1 ;
2004-03-22 18:22:58 +03:00
}
2003-10-21 02:32:39 +04:00
sum = 0 ;
while ( ( lk = xmlListFront ( writer - > nodes ) ) ! = NULL ) {
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
if ( p = = 0 )
break ;
switch ( p - > state ) {
case XML_TEXTWRITER_NAME :
case XML_TEXTWRITER_ATTRIBUTE :
case XML_TEXTWRITER_TEXT :
count = xmlTextWriterEndElement ( writer ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
break ;
case XML_TEXTWRITER_PI :
case XML_TEXTWRITER_PI_TEXT :
count = xmlTextWriterEndPI ( writer ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
break ;
case XML_TEXTWRITER_CDATA :
count = xmlTextWriterEndCDATA ( writer ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
break ;
case XML_TEXTWRITER_DTD :
2004-03-22 18:22:58 +03:00
case XML_TEXTWRITER_DTD_TEXT :
case XML_TEXTWRITER_DTD_ELEM :
case XML_TEXTWRITER_DTD_ELEM_TEXT :
case XML_TEXTWRITER_DTD_ATTL :
case XML_TEXTWRITER_DTD_ATTL_TEXT :
case XML_TEXTWRITER_DTD_ENTY :
case XML_TEXTWRITER_DTD_ENTY_TEXT :
case XML_TEXTWRITER_DTD_PENT :
2003-10-21 02:32:39 +04:00
count = xmlTextWriterEndDTD ( writer ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
break ;
2004-02-17 14:40:32 +03:00
case XML_TEXTWRITER_COMMENT :
count = xmlTextWriterEndComment ( writer ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
break ;
2003-10-21 02:32:39 +04:00
default :
2004-02-17 14:40:32 +03:00
break ;
2003-10-21 02:32:39 +04:00
}
}
2004-01-02 23:04:23 +03:00
if ( ! writer - > indent ) {
2004-02-17 14:40:32 +03:00
count = xmlOutputBufferWriteString ( writer - > out , " \n " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
}
2008-02-13 13:17:41 +03:00
sum + = xmlTextWriterFlush ( writer ) ;
2004-02-17 14:40:32 +03:00
return sum ;
}
/**
* xmlTextWriterStartComment :
* @ writer : the xmlTextWriterPtr
*
* Start an xml comment .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterStartComment ( xmlTextWriterPtr writer )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
2004-03-22 18:22:58 +03:00
if ( writer = = NULL ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_INTERNAL_ERROR ,
2004-03-22 18:22:58 +03:00
" xmlTextWriterStartComment : invalid writer! \n " ) ;
2004-02-17 14:40:32 +03:00
return - 1 ;
2004-03-22 18:22:58 +03:00
}
2004-02-17 14:40:32 +03:00
sum = 0 ;
lk = xmlListFront ( writer - > nodes ) ;
if ( lk ! = 0 ) {
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
if ( p ! = 0 ) {
switch ( p - > state ) {
case XML_TEXTWRITER_TEXT :
case XML_TEXTWRITER_NONE :
break ;
case XML_TEXTWRITER_NAME :
2007-06-08 12:50:47 +04:00
/* Output namespace declarations */
count = xmlTextWriterOutputNSDecl ( writer ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
2004-02-17 14:40:32 +03:00
count = xmlOutputBufferWriteString ( writer - > out , " > " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
2004-03-22 18:22:58 +03:00
if ( writer - > indent ) {
count =
xmlOutputBufferWriteString ( writer - > out , " \n " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
}
2004-02-17 14:40:32 +03:00
p - > state = XML_TEXTWRITER_TEXT ;
break ;
default :
return - 1 ;
}
}
}
p = ( xmlTextWriterStackEntry * )
xmlMalloc ( sizeof ( xmlTextWriterStackEntry ) ) ;
if ( p = = 0 ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_NO_MEMORY ,
2004-02-17 14:40:32 +03:00
" xmlTextWriterStartElement : out of memory! \n " ) ;
return - 1 ;
}
2005-07-30 02:02:24 +04:00
p - > name = NULL ;
2004-02-17 14:40:32 +03:00
p - > state = XML_TEXTWRITER_COMMENT ;
xmlListPushFront ( writer - > nodes , p ) ;
if ( writer - > indent ) {
count = xmlTextWriterWriteIndent ( writer ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
}
count = xmlOutputBufferWriteString ( writer - > out , " <!-- " ) ;
if ( count < 0 )
2003-11-20 14:59:09 +03:00
return - 1 ;
sum + = count ;
2004-02-17 14:40:32 +03:00
return sum ;
}
/**
* xmlTextWriterEndComment :
* @ writer : the xmlTextWriterPtr
*
2019-09-30 18:04:54 +03:00
* End the current xml comment .
2004-02-17 14:40:32 +03:00
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterEndComment ( xmlTextWriterPtr writer )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
2004-03-22 18:22:58 +03:00
if ( writer = = NULL ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_INTERNAL_ERROR ,
2004-03-22 18:22:58 +03:00
" xmlTextWriterEndComment : invalid writer! \n " ) ;
2004-02-17 14:40:32 +03:00
return - 1 ;
2004-03-22 18:22:58 +03:00
}
2004-02-17 14:40:32 +03:00
lk = xmlListFront ( writer - > nodes ) ;
2004-03-22 18:22:58 +03:00
if ( lk = = 0 ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_INTERNAL_ERROR ,
2004-03-22 18:22:58 +03:00
" xmlTextWriterEndComment : not allowed in this context! \n " ) ;
2004-02-17 14:40:32 +03:00
return - 1 ;
2004-03-22 18:22:58 +03:00
}
2004-02-17 14:40:32 +03:00
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
if ( p = = 0 )
return - 1 ;
sum = 0 ;
switch ( p - > state ) {
case XML_TEXTWRITER_COMMENT :
count = xmlOutputBufferWriteString ( writer - > out , " --> " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
break ;
default :
return - 1 ;
}
if ( writer - > indent ) {
count = xmlOutputBufferWriteString ( writer - > out , " \n " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
2004-01-02 23:04:23 +03:00
}
2004-02-17 14:40:32 +03:00
xmlListPopFront ( writer - > nodes ) ;
2003-10-21 02:32:39 +04:00
return sum ;
}
/**
* xmlTextWriterWriteFormatComment :
* @ writer : the xmlTextWriterPtr
* @ format : format string ( see printf )
2003-11-21 03:28:39 +03:00
* @ . . . : extra parameters for the format
2003-10-21 02:32:39 +04:00
*
* Write an xml comment .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2005-07-21 17:24:09 +04:00
int XMLCDECL
2003-10-21 02:32:39 +04:00
xmlTextWriterWriteFormatComment ( xmlTextWriterPtr writer ,
const char * format , . . . )
{
int rc ;
va_list ap ;
va_start ( ap , format ) ;
rc = xmlTextWriterWriteVFormatComment ( writer , format , ap ) ;
va_end ( ap ) ;
return rc ;
}
/**
* xmlTextWriterWriteVFormatComment :
* @ writer : the xmlTextWriterPtr
* @ format : format string ( see printf )
* @ argptr : pointer to the first member of the variable argument list .
*
* Write an xml comment .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterWriteVFormatComment ( xmlTextWriterPtr writer ,
const char * format , va_list argptr )
{
int rc ;
xmlChar * buf ;
2004-03-22 18:22:58 +03:00
if ( writer = = NULL ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_INTERNAL_ERROR ,
2004-03-22 18:22:58 +03:00
" xmlTextWriterWriteVFormatComment : invalid writer! \n " ) ;
2003-10-21 02:32:39 +04:00
return - 1 ;
2004-03-22 18:22:58 +03:00
}
2003-10-21 02:32:39 +04:00
buf = xmlTextWriterVSprintf ( format , argptr ) ;
2009-02-20 11:40:55 +03:00
if ( buf = = NULL )
return - 1 ;
2003-10-21 02:32:39 +04:00
rc = xmlTextWriterWriteComment ( writer , buf ) ;
xmlFree ( buf ) ;
return rc ;
}
/**
* xmlTextWriterWriteComment :
* @ writer : the xmlTextWriterPtr
* @ content : comment string
*
* Write an xml comment .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterWriteComment ( xmlTextWriterPtr writer , const xmlChar * content )
{
int count ;
int sum ;
sum = 0 ;
2004-02-17 14:40:32 +03:00
count = xmlTextWriterStartComment ( writer ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
2004-02-17 14:40:32 +03:00
count = xmlTextWriterWriteString ( writer , content ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
2004-02-17 14:40:32 +03:00
count = xmlTextWriterEndComment ( writer ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
return sum ;
}
/**
* xmlTextWriterStartElement :
* @ writer : the xmlTextWriterPtr
* @ name : element name
*
* Start an xml element .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterStartElement ( xmlTextWriterPtr writer , const xmlChar * name )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
if ( ( writer = = NULL ) | | ( name = = NULL ) | | ( * name = = ' \0 ' ) )
return - 1 ;
sum = 0 ;
lk = xmlListFront ( writer - > nodes ) ;
if ( lk ! = 0 ) {
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
if ( p ! = 0 ) {
switch ( p - > state ) {
case XML_TEXTWRITER_PI :
case XML_TEXTWRITER_PI_TEXT :
return - 1 ;
case XML_TEXTWRITER_NONE :
break ;
2005-02-23 17:05:37 +03:00
case XML_TEXTWRITER_ATTRIBUTE :
count = xmlTextWriterEndAttribute ( writer ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
/* fallthrough */
2003-10-21 02:32:39 +04:00
case XML_TEXTWRITER_NAME :
2007-06-08 12:50:47 +04:00
/* Output namespace declarations */
count = xmlTextWriterOutputNSDecl ( writer ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
2003-10-21 02:32:39 +04:00
count = xmlOutputBufferWriteString ( writer - > out , " > " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
2004-02-17 14:40:32 +03:00
if ( writer - > indent )
count =
xmlOutputBufferWriteString ( writer - > out , " \n " ) ;
2003-10-21 02:32:39 +04:00
p - > state = XML_TEXTWRITER_TEXT ;
break ;
2004-02-17 14:40:32 +03:00
default :
break ;
2003-10-21 02:32:39 +04:00
}
}
}
p = ( xmlTextWriterStackEntry * )
xmlMalloc ( sizeof ( xmlTextWriterStackEntry ) ) ;
if ( p = = 0 ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_NO_MEMORY ,
2003-10-21 02:32:39 +04:00
" xmlTextWriterStartElement : out of memory! \n " ) ;
return - 1 ;
}
p - > name = xmlStrdup ( name ) ;
if ( p - > name = = 0 ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_NO_MEMORY ,
2003-10-21 02:32:39 +04:00
" xmlTextWriterStartElement : out of memory! \n " ) ;
xmlFree ( p ) ;
return - 1 ;
}
p - > state = XML_TEXTWRITER_NAME ;
xmlListPushFront ( writer - > nodes , p ) ;
2004-02-17 14:40:32 +03:00
if ( writer - > indent ) {
count = xmlTextWriterWriteIndent ( writer ) ;
sum + = count ;
2004-01-02 23:04:23 +03:00
}
2003-10-21 02:32:39 +04:00
count = xmlOutputBufferWriteString ( writer - > out , " < " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
2003-11-20 14:59:09 +03:00
count =
xmlOutputBufferWriteString ( writer - > out , ( const char * ) p - > name ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
return sum ;
}
/**
* xmlTextWriterStartElementNS :
* @ writer : the xmlTextWriterPtr
* @ prefix : namespace prefix or NULL
* @ name : element local name
* @ namespaceURI : namespace URI or NULL
*
* Start an xml element with namespace support .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterStartElementNS ( xmlTextWriterPtr writer ,
const xmlChar * prefix , const xmlChar * name ,
const xmlChar * namespaceURI )
{
int count ;
int sum ;
xmlChar * buf ;
if ( ( writer = = NULL ) | | ( name = = NULL ) | | ( * name = = ' \0 ' ) )
return - 1 ;
2005-07-30 02:02:24 +04:00
buf = NULL ;
2003-10-21 02:32:39 +04:00
if ( prefix ! = 0 ) {
buf = xmlStrdup ( prefix ) ;
buf = xmlStrcat ( buf , BAD_CAST " : " ) ;
}
buf = xmlStrcat ( buf , name ) ;
sum = 0 ;
count = xmlTextWriterStartElement ( writer , buf ) ;
xmlFree ( buf ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
if ( namespaceURI ! = 0 ) {
2012-09-11 09:26:36 +04:00
xmlTextWriterNsStackEntry * p = ( xmlTextWriterNsStackEntry * )
2007-06-08 12:50:47 +04:00
xmlMalloc ( sizeof ( xmlTextWriterNsStackEntry ) ) ;
if ( p = = 0 ) {
2012-09-11 09:26:36 +04:00
xmlWriterErrMsg ( writer , XML_ERR_NO_MEMORY ,
2007-06-08 12:50:47 +04:00
" xmlTextWriterStartElementNS : out of memory! \n " ) ;
return - 1 ;
}
2003-10-21 02:32:39 +04:00
buf = xmlStrdup ( BAD_CAST " xmlns " ) ;
if ( prefix ! = 0 ) {
buf = xmlStrcat ( buf , BAD_CAST " : " ) ;
buf = xmlStrcat ( buf , prefix ) ;
}
2007-06-08 12:50:47 +04:00
p - > prefix = buf ;
p - > uri = xmlStrdup ( namespaceURI ) ;
if ( p - > uri = = 0 ) {
xmlWriterErrMsg ( writer , XML_ERR_NO_MEMORY ,
" xmlTextWriterStartElementNS : out of memory! \n " ) ;
xmlFree ( p ) ;
2003-10-21 02:32:39 +04:00
return - 1 ;
2007-06-08 12:50:47 +04:00
}
p - > elem = xmlListFront ( writer - > nodes ) ;
xmlListPushFront ( writer - > nsstack , p ) ;
2003-10-21 02:32:39 +04:00
}
return sum ;
}
/**
* xmlTextWriterEndElement :
* @ writer : the xmlTextWriterPtr
*
* End the current xml element .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterEndElement ( xmlTextWriterPtr writer )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
if ( writer = = NULL )
return - 1 ;
lk = xmlListFront ( writer - > nodes ) ;
2007-06-08 12:50:47 +04:00
if ( lk = = 0 ) {
xmlListDelete ( writer - > nsstack ) ;
writer - > nsstack = NULL ;
2003-10-21 02:32:39 +04:00
return - 1 ;
2007-06-08 12:50:47 +04:00
}
2003-10-21 02:32:39 +04:00
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
2007-06-08 12:50:47 +04:00
if ( p = = 0 ) {
xmlListDelete ( writer - > nsstack ) ;
writer - > nsstack = NULL ;
2003-10-21 02:32:39 +04:00
return - 1 ;
2007-06-08 12:50:47 +04:00
}
2003-10-21 02:32:39 +04:00
sum = 0 ;
switch ( p - > state ) {
case XML_TEXTWRITER_ATTRIBUTE :
count = xmlTextWriterEndAttribute ( writer ) ;
2007-06-08 12:50:47 +04:00
if ( count < 0 ) {
xmlListDelete ( writer - > nsstack ) ;
writer - > nsstack = NULL ;
2003-10-21 02:32:39 +04:00
return - 1 ;
2007-06-08 12:50:47 +04:00
}
2003-10-21 02:32:39 +04:00
sum + = count ;
/* fallthrough */
case XML_TEXTWRITER_NAME :
2007-06-08 12:50:47 +04:00
/* Output namespace declarations */
count = xmlTextWriterOutputNSDecl ( writer ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
2004-02-17 14:40:32 +03:00
if ( writer - > indent ) /* next element needs indent */
writer - > doindent = 1 ;
2003-10-21 02:32:39 +04:00
count = xmlOutputBufferWriteString ( writer - > out , " /> " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
break ;
case XML_TEXTWRITER_TEXT :
2004-02-17 14:40:32 +03:00
if ( ( writer - > indent ) & & ( writer - > doindent ) ) {
count = xmlTextWriterWriteIndent ( writer ) ;
sum + = count ;
writer - > doindent = 1 ;
} else
writer - > doindent = 1 ;
2003-10-21 02:32:39 +04:00
count = xmlOutputBufferWriteString ( writer - > out , " </ " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWriteString ( writer - > out ,
2004-02-17 14:40:32 +03:00
( const char * ) p - > name ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWriteString ( writer - > out , " > " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
break ;
default :
return - 1 ;
}
2004-01-02 23:04:23 +03:00
if ( writer - > indent ) {
2004-02-17 14:40:32 +03:00
count = xmlOutputBufferWriteString ( writer - > out , " \n " ) ;
sum + = count ;
2004-01-02 23:04:23 +03:00
}
2003-10-21 02:32:39 +04:00
xmlListPopFront ( writer - > nodes ) ;
return sum ;
}
/**
* xmlTextWriterFullEndElement :
* @ writer : the xmlTextWriterPtr
*
* End the current xml element . Writes an end tag even if the element is empty
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterFullEndElement ( xmlTextWriterPtr writer )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
if ( writer = = NULL )
return - 1 ;
lk = xmlListFront ( writer - > nodes ) ;
if ( lk = = 0 )
return - 1 ;
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
if ( p = = 0 )
return - 1 ;
sum = 0 ;
switch ( p - > state ) {
case XML_TEXTWRITER_ATTRIBUTE :
count = xmlTextWriterEndAttribute ( writer ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
/* fallthrough */
case XML_TEXTWRITER_NAME :
2007-06-08 12:50:47 +04:00
/* Output namespace declarations */
count = xmlTextWriterOutputNSDecl ( writer ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
2003-10-21 02:32:39 +04:00
count = xmlOutputBufferWriteString ( writer - > out , " > " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
2008-12-27 16:17:43 +03:00
if ( writer - > indent )
writer - > doindent = 0 ;
2003-10-21 02:32:39 +04:00
/* fallthrough */
case XML_TEXTWRITER_TEXT :
2008-12-27 16:17:43 +03:00
if ( ( writer - > indent ) & & ( writer - > doindent ) ) {
count = xmlTextWriterWriteIndent ( writer ) ;
sum + = count ;
writer - > doindent = 1 ;
} else
writer - > doindent = 1 ;
2003-10-21 02:32:39 +04:00
count = xmlOutputBufferWriteString ( writer - > out , " </ " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWriteString ( writer - > out ,
2004-02-17 14:40:32 +03:00
( const char * ) p - > name ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWriteString ( writer - > out , " > " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
break ;
default :
return - 1 ;
}
2008-01-09 05:19:50 +03:00
if ( writer - > indent ) {
count = xmlOutputBufferWriteString ( writer - > out , " \n " ) ;
sum + = count ;
}
2003-10-21 02:32:39 +04:00
xmlListPopFront ( writer - > nodes ) ;
return sum ;
}
/**
* xmlTextWriterWriteFormatRaw :
* @ writer : the xmlTextWriterPtr
* @ format : format string ( see printf )
2003-11-21 03:28:39 +03:00
* @ . . . : extra parameters for the format
2003-10-21 02:32:39 +04:00
*
* Write a formatted raw xml text .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2005-07-21 17:24:09 +04:00
int XMLCDECL
2003-10-21 02:32:39 +04:00
xmlTextWriterWriteFormatRaw ( xmlTextWriterPtr writer , const char * format ,
. . . )
{
int rc ;
va_list ap ;
va_start ( ap , format ) ;
rc = xmlTextWriterWriteVFormatRaw ( writer , format , ap ) ;
va_end ( ap ) ;
return rc ;
}
/**
* xmlTextWriterWriteVFormatRaw :
* @ writer : the xmlTextWriterPtr
* @ format : format string ( see printf )
* @ argptr : pointer to the first member of the variable argument list .
*
* Write a formatted raw xml text .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterWriteVFormatRaw ( xmlTextWriterPtr writer , const char * format ,
va_list argptr )
{
int rc ;
xmlChar * buf ;
if ( writer = = NULL )
return - 1 ;
buf = xmlTextWriterVSprintf ( format , argptr ) ;
2009-02-20 11:40:55 +03:00
if ( buf = = NULL )
return - 1 ;
2003-10-21 02:32:39 +04:00
rc = xmlTextWriterWriteRaw ( writer , buf ) ;
xmlFree ( buf ) ;
return rc ;
}
/**
2003-12-05 17:57:46 +03:00
* xmlTextWriterWriteRawLen :
2003-10-21 02:32:39 +04:00
* @ writer : the xmlTextWriterPtr
* @ content : text string
* @ len : length of the text string
*
* Write an xml text .
* TODO : what about entities and special chars ? ?
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterWriteRawLen ( xmlTextWriterPtr writer , const xmlChar * content ,
int len )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
2004-03-22 18:22:58 +03:00
if ( writer = = NULL ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_INTERNAL_ERROR ,
2004-03-22 18:22:58 +03:00
" xmlTextWriterWriteRawLen : invalid writer! \n " ) ;
2003-10-21 02:32:39 +04:00
return - 1 ;
2004-03-22 18:22:58 +03:00
}
2003-10-21 02:32:39 +04:00
2004-11-03 14:50:29 +03:00
if ( ( content = = NULL ) | | ( len < 0 ) ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_INTERNAL_ERROR ,
2004-03-22 18:22:58 +03:00
" xmlTextWriterWriteRawLen : invalid content! \n " ) ;
return - 1 ;
}
2003-10-21 02:32:39 +04:00
sum = 0 ;
2004-03-22 18:22:58 +03:00
lk = xmlListFront ( writer - > nodes ) ;
if ( lk ! = 0 ) {
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
count = xmlTextWriterHandleStateDependencies ( writer , p ) ;
if ( count < 0 )
2003-10-21 02:32:39 +04:00
return - 1 ;
2004-03-22 18:22:58 +03:00
sum + = count ;
2003-10-21 02:32:39 +04:00
}
2004-03-22 18:22:58 +03:00
if ( writer - > indent )
writer - > doindent = 0 ;
if ( content ! = NULL ) {
count =
xmlOutputBufferWrite ( writer - > out , len , ( const char * ) content ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
}
2003-10-21 02:32:39 +04:00
return sum ;
}
/**
* xmlTextWriterWriteRaw :
* @ writer : the xmlTextWriterPtr
* @ content : text string
*
* Write a raw xml text .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterWriteRaw ( xmlTextWriterPtr writer , const xmlChar * content )
{
return xmlTextWriterWriteRawLen ( writer , content , xmlStrlen ( content ) ) ;
}
/**
* xmlTextWriterWriteFormatString :
* @ writer : the xmlTextWriterPtr
* @ format : format string ( see printf )
2003-11-21 03:28:39 +03:00
* @ . . . : extra parameters for the format
2003-10-21 02:32:39 +04:00
*
* Write a formatted xml text .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2005-07-21 17:24:09 +04:00
int XMLCDECL
2003-10-21 02:32:39 +04:00
xmlTextWriterWriteFormatString ( xmlTextWriterPtr writer , const char * format ,
. . . )
{
int rc ;
va_list ap ;
2004-11-03 14:50:29 +03:00
if ( ( writer = = NULL ) | | ( format = = NULL ) )
return - 1 ;
2003-10-21 02:32:39 +04:00
va_start ( ap , format ) ;
rc = xmlTextWriterWriteVFormatString ( writer , format , ap ) ;
va_end ( ap ) ;
return rc ;
}
/**
* xmlTextWriterWriteVFormatString :
* @ writer : the xmlTextWriterPtr
* @ format : format string ( see printf )
* @ argptr : pointer to the first member of the variable argument list .
*
* Write a formatted xml text .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterWriteVFormatString ( xmlTextWriterPtr writer ,
const char * format , va_list argptr )
{
int rc ;
xmlChar * buf ;
2004-11-03 14:50:29 +03:00
if ( ( writer = = NULL ) | | ( format = = NULL ) )
2003-10-21 02:32:39 +04:00
return - 1 ;
buf = xmlTextWriterVSprintf ( format , argptr ) ;
2009-02-20 11:40:55 +03:00
if ( buf = = NULL )
return - 1 ;
2003-10-21 02:32:39 +04:00
rc = xmlTextWriterWriteString ( writer , buf ) ;
xmlFree ( buf ) ;
return rc ;
}
/**
* xmlTextWriterWriteString :
* @ writer : the xmlTextWriterPtr
* @ content : text string
*
* Write an xml text .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterWriteString ( xmlTextWriterPtr writer , const xmlChar * content )
{
2004-03-22 18:22:58 +03:00
int count ;
2003-10-21 02:32:39 +04:00
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
2004-03-22 18:22:58 +03:00
xmlChar * buf ;
2003-10-21 02:32:39 +04:00
2004-11-03 14:50:29 +03:00
if ( ( writer = = NULL ) | | ( content = = NULL ) )
2003-10-21 02:32:39 +04:00
return - 1 ;
sum = 0 ;
2004-03-22 18:22:58 +03:00
buf = ( xmlChar * ) content ;
lk = xmlListFront ( writer - > nodes ) ;
if ( lk ! = 0 ) {
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
if ( p ! = 0 ) {
switch ( p - > state ) {
case XML_TEXTWRITER_NAME :
case XML_TEXTWRITER_TEXT :
2004-05-17 07:17:26 +04:00
#if 0
buf = NULL ;
xmlOutputBufferWriteEscape ( writer - > out , content , NULL ) ;
# endif
2004-03-22 18:22:58 +03:00
buf = xmlEncodeSpecialChars ( NULL , content ) ;
break ;
case XML_TEXTWRITER_ATTRIBUTE :
buf = NULL ;
2012-07-16 10:54:45 +04:00
xmlBufAttrSerializeTxtContent ( writer - > out - > buffer ,
writer - > doc , NULL , content ) ;
2004-03-22 18:22:58 +03:00
break ;
2004-04-17 18:58:15 +04:00
default :
break ;
2004-03-22 18:22:58 +03:00
}
}
2003-10-21 02:32:39 +04:00
}
2004-03-22 18:22:58 +03:00
if ( buf ! = NULL ) {
count = xmlTextWriterWriteRaw ( writer , buf ) ;
2004-01-05 16:05:58 +03:00
2004-03-22 18:22:58 +03:00
if ( buf ! = content ) /* buf was allocated by us, so free it */
xmlFree ( buf ) ;
2009-02-20 11:19:53 +03:00
if ( count < 0 )
return - 1 ;
sum + = count ;
2004-02-01 13:04:05 +03:00
}
2003-10-21 02:32:39 +04:00
return sum ;
}
/**
* xmlOutputBufferWriteBase64 :
* @ out : the xmlOutputBufferPtr
* @ data : binary data
* @ len : the number of bytes to encode
*
* Write base64 encoded data to an xmlOutputBuffer .
* Adapted from John Walker ' s base64 . c ( http : //www.fourmilab.ch/).
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
static int
xmlOutputBufferWriteBase64 ( xmlOutputBufferPtr out , int len ,
const unsigned char * data )
{
static unsigned char dtable [ 64 ] =
2004-09-11 20:09:09 +04:00
{ ' A ' , ' B ' , ' C ' , ' D ' , ' E ' , ' F ' , ' G ' , ' H ' , ' I ' , ' J ' , ' K ' , ' L ' , ' M ' ,
' N ' , ' O ' , ' P ' , ' Q ' , ' R ' , ' S ' , ' T ' , ' U ' , ' V ' , ' W ' , ' X ' , ' Y ' , ' Z ' ,
' a ' , ' b ' , ' c ' , ' d ' , ' e ' , ' f ' , ' g ' , ' h ' , ' i ' , ' j ' , ' k ' , ' l ' , ' m ' ,
' n ' , ' o ' , ' p ' , ' q ' , ' r ' , ' s ' , ' t ' , ' u ' , ' v ' , ' w ' , ' x ' , ' y ' , ' z ' ,
' 0 ' , ' 1 ' , ' 2 ' , ' 3 ' , ' 4 ' , ' 5 ' , ' 6 ' , ' 7 ' , ' 8 ' , ' 9 ' , ' + ' , ' / ' } ;
2003-10-21 02:32:39 +04:00
int i ;
int linelen ;
int count ;
int sum ;
2004-11-03 14:50:29 +03:00
if ( ( out = = NULL ) | | ( len < 0 ) | | ( data = = NULL ) )
return ( - 1 ) ;
2003-10-21 02:32:39 +04:00
linelen = 0 ;
sum = 0 ;
i = 0 ;
while ( 1 ) {
unsigned char igroup [ 3 ] ;
unsigned char ogroup [ 4 ] ;
int c ;
int n ;
igroup [ 0 ] = igroup [ 1 ] = igroup [ 2 ] = 0 ;
for ( n = 0 ; n < 3 & & i < len ; n + + , i + + ) {
c = data [ i ] ;
igroup [ n ] = ( unsigned char ) c ;
}
if ( n > 0 ) {
ogroup [ 0 ] = dtable [ igroup [ 0 ] > > 2 ] ;
ogroup [ 1 ] = dtable [ ( ( igroup [ 0 ] & 3 ) < < 4 ) | ( igroup [ 1 ] > > 4 ) ] ;
ogroup [ 2 ] =
dtable [ ( ( igroup [ 1 ] & 0xF ) < < 2 ) | ( igroup [ 2 ] > > 6 ) ] ;
ogroup [ 3 ] = dtable [ igroup [ 2 ] & 0x3F ] ;
if ( n < 3 ) {
ogroup [ 3 ] = ' = ' ;
if ( n < 2 ) {
ogroup [ 2 ] = ' = ' ;
}
}
if ( linelen > = B64LINELEN ) {
count = xmlOutputBufferWrite ( out , 2 , B64CRLF ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
linelen = 0 ;
}
count = xmlOutputBufferWrite ( out , 4 , ( const char * ) ogroup ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
linelen + = 4 ;
}
2003-10-22 16:34:36 +04:00
if ( i > = len )
break ;
2003-10-21 02:32:39 +04:00
}
return sum ;
}
/**
* xmlTextWriterWriteBase64 :
* @ writer : the xmlTextWriterPtr
* @ data : binary data
* @ start : the position within the data of the first byte to encode
* @ len : the number of bytes to encode
*
* Write an base64 encoded xml text .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
2004-02-17 14:40:32 +03:00
xmlTextWriterWriteBase64 ( xmlTextWriterPtr writer , const char * data ,
2003-10-21 02:32:39 +04:00
int start , int len )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
2004-11-03 14:50:29 +03:00
if ( ( writer = = NULL ) | | ( data = = NULL ) | | ( start < 0 ) | | ( len < 0 ) )
2003-10-21 02:32:39 +04:00
return - 1 ;
sum = 0 ;
2004-03-22 18:22:58 +03:00
lk = xmlListFront ( writer - > nodes ) ;
if ( lk ! = 0 ) {
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
if ( p ! = 0 ) {
count = xmlTextWriterHandleStateDependencies ( writer , p ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
2004-03-22 18:22:58 +03:00
}
2003-10-21 02:32:39 +04:00
}
2004-02-17 14:40:32 +03:00
if ( writer - > indent )
writer - > doindent = 0 ;
2003-10-21 02:32:39 +04:00
count =
xmlOutputBufferWriteBase64 ( writer - > out , len ,
( unsigned char * ) data + start ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
return sum ;
}
/**
* xmlOutputBufferWriteBinHex :
* @ out : the xmlOutputBufferPtr
* @ data : binary data
* @ len : the number of bytes to encode
*
* Write hqx encoded data to an xmlOutputBuffer .
* : : todo
*
2012-09-11 09:26:36 +04:00
* Returns the bytes written ( may be 0 because of buffering )
2004-09-11 20:09:09 +04:00
* or - 1 in case of error
2003-10-21 02:32:39 +04:00
*/
static int
2004-02-17 14:40:32 +03:00
xmlOutputBufferWriteBinHex ( xmlOutputBufferPtr out ,
int len , const unsigned char * data )
2003-10-21 02:32:39 +04:00
{
2004-02-17 14:40:32 +03:00
int count ;
int sum ;
2012-09-11 09:26:36 +04:00
static char hex [ 16 ] =
{ ' 0 ' , ' 1 ' , ' 2 ' , ' 3 ' , ' 4 ' , ' 5 ' , ' 6 ' , ' 7 ' , ' 8 ' , ' 9 ' , ' A ' , ' B ' , ' C ' , ' D ' , ' E ' , ' F ' } ;
2004-02-17 14:40:32 +03:00
int i ;
2004-11-03 14:50:29 +03:00
if ( ( out = = NULL ) | | ( data = = NULL ) | | ( len < 0 ) ) {
2004-02-17 14:40:32 +03:00
return - 1 ;
}
sum = 0 ;
for ( i = 0 ; i < len ; i + + ) {
count =
xmlOutputBufferWrite ( out , 1 ,
( const char * ) & hex [ data [ i ] > > 4 ] ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
count =
xmlOutputBufferWrite ( out , 1 ,
( const char * ) & hex [ data [ i ] & 0xF ] ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
}
return sum ;
2003-10-21 02:32:39 +04:00
}
/**
* xmlTextWriterWriteBinHex :
* @ writer : the xmlTextWriterPtr
* @ data : binary data
* @ start : the position within the data of the first byte to encode
* @ len : the number of bytes to encode
*
* Write a BinHex encoded xml text .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
2004-02-17 14:40:32 +03:00
xmlTextWriterWriteBinHex ( xmlTextWriterPtr writer , const char * data ,
2003-10-21 02:32:39 +04:00
int start , int len )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
2004-11-03 14:50:29 +03:00
if ( ( writer = = NULL ) | | ( data = = NULL ) | | ( start < 0 ) | | ( len < 0 ) )
2003-10-21 02:32:39 +04:00
return - 1 ;
sum = 0 ;
2004-03-22 18:22:58 +03:00
lk = xmlListFront ( writer - > nodes ) ;
if ( lk ! = 0 ) {
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
if ( p ! = 0 ) {
count = xmlTextWriterHandleStateDependencies ( writer , p ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
2004-03-22 18:22:58 +03:00
}
2003-10-21 02:32:39 +04:00
}
2004-02-17 14:40:32 +03:00
if ( writer - > indent )
writer - > doindent = 0 ;
2003-10-21 02:32:39 +04:00
count =
xmlOutputBufferWriteBinHex ( writer - > out , len ,
( unsigned char * ) data + start ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
return sum ;
}
/**
* xmlTextWriterStartAttribute :
* @ writer : the xmlTextWriterPtr
* @ name : element name
*
* Start an xml attribute .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterStartAttribute ( xmlTextWriterPtr writer , const xmlChar * name )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
if ( ( writer = = NULL ) | | ( name = = NULL ) | | ( * name = = ' \0 ' ) )
return - 1 ;
sum = 0 ;
lk = xmlListFront ( writer - > nodes ) ;
if ( lk = = 0 )
return - 1 ;
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
if ( p = = 0 )
return - 1 ;
switch ( p - > state ) {
case XML_TEXTWRITER_ATTRIBUTE :
count = xmlTextWriterEndAttribute ( writer ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
/* fallthrough */
case XML_TEXTWRITER_NAME :
count = xmlOutputBufferWriteString ( writer - > out , " " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
2003-11-20 14:59:09 +03:00
count =
xmlOutputBufferWriteString ( writer - > out ,
( const char * ) name ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWriteString ( writer - > out , " = " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWrite ( writer - > out , 1 , & writer - > qchar ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
p - > state = XML_TEXTWRITER_ATTRIBUTE ;
break ;
default :
return - 1 ;
}
return sum ;
}
/**
* xmlTextWriterStartAttributeNS :
* @ writer : the xmlTextWriterPtr
* @ prefix : namespace prefix or NULL
* @ name : element local name
* @ namespaceURI : namespace URI or NULL
*
* Start an xml attribute with namespace support .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterStartAttributeNS ( xmlTextWriterPtr writer ,
const xmlChar * prefix , const xmlChar * name ,
const xmlChar * namespaceURI )
{
int count ;
int sum ;
xmlChar * buf ;
xmlTextWriterNsStackEntry * p ;
if ( ( writer = = NULL ) | | ( name = = NULL ) | | ( * name = = ' \0 ' ) )
return - 1 ;
2007-06-08 12:50:47 +04:00
/* Handle namespace first in case of error */
if ( namespaceURI ! = 0 ) {
xmlTextWriterNsStackEntry nsentry , * curns ;
buf = xmlStrdup ( BAD_CAST " xmlns " ) ;
if ( prefix ! = 0 ) {
buf = xmlStrcat ( buf , BAD_CAST " : " ) ;
buf = xmlStrcat ( buf , prefix ) ;
}
nsentry . prefix = buf ;
nsentry . uri = ( xmlChar * ) namespaceURI ;
nsentry . elem = xmlListFront ( writer - > nodes ) ;
2012-09-11 09:26:36 +04:00
curns = ( xmlTextWriterNsStackEntry * ) xmlListSearch ( writer - > nsstack ,
2007-06-08 12:50:47 +04:00
( void * ) & nsentry ) ;
if ( ( curns ! = NULL ) ) {
xmlFree ( buf ) ;
if ( xmlStrcmp ( curns - > uri , namespaceURI ) = = 0 ) {
/* Namespace already defined on element skip */
buf = NULL ;
} else {
/* Prefix mismatch so error out */
return - 1 ;
}
}
/* Do not add namespace decl to list - it is already there */
if ( buf ! = NULL ) {
p = ( xmlTextWriterNsStackEntry * )
xmlMalloc ( sizeof ( xmlTextWriterNsStackEntry ) ) ;
if ( p = = 0 ) {
xmlWriterErrMsg ( writer , XML_ERR_NO_MEMORY ,
" xmlTextWriterStartAttributeNS : out of memory! \n " ) ;
return - 1 ;
}
p - > prefix = buf ;
p - > uri = xmlStrdup ( namespaceURI ) ;
if ( p - > uri = = 0 ) {
xmlWriterErrMsg ( writer , XML_ERR_NO_MEMORY ,
" xmlTextWriterStartAttributeNS : out of memory! \n " ) ;
xmlFree ( p ) ;
return - 1 ;
}
p - > elem = xmlListFront ( writer - > nodes ) ;
xmlListPushFront ( writer - > nsstack , p ) ;
}
}
2005-07-30 02:02:24 +04:00
buf = NULL ;
2003-10-21 02:32:39 +04:00
if ( prefix ! = 0 ) {
buf = xmlStrdup ( prefix ) ;
buf = xmlStrcat ( buf , BAD_CAST " : " ) ;
}
buf = xmlStrcat ( buf , name ) ;
sum = 0 ;
count = xmlTextWriterStartAttribute ( writer , buf ) ;
xmlFree ( buf ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
return sum ;
}
/**
* xmlTextWriterEndAttribute :
* @ writer : the xmlTextWriterPtr
*
* End the current xml element .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterEndAttribute ( xmlTextWriterPtr writer )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
if ( writer = = NULL )
return - 1 ;
lk = xmlListFront ( writer - > nodes ) ;
if ( lk = = 0 ) {
return - 1 ;
}
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
if ( p = = 0 ) {
return - 1 ;
}
sum = 0 ;
switch ( p - > state ) {
case XML_TEXTWRITER_ATTRIBUTE :
p - > state = XML_TEXTWRITER_NAME ;
count = xmlOutputBufferWrite ( writer - > out , 1 , & writer - > qchar ) ;
if ( count < 0 ) {
return - 1 ;
}
sum + = count ;
break ;
default :
return - 1 ;
}
return sum ;
}
/**
* xmlTextWriterWriteFormatAttribute :
* @ writer : the xmlTextWriterPtr
* @ name : attribute name
* @ format : format string ( see printf )
2003-11-21 03:28:39 +03:00
* @ . . . : extra parameters for the format
2003-10-21 02:32:39 +04:00
*
* Write a formatted xml attribute .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2005-07-21 17:24:09 +04:00
int XMLCDECL
2003-10-21 02:32:39 +04:00
xmlTextWriterWriteFormatAttribute ( xmlTextWriterPtr writer ,
const xmlChar * name , const char * format ,
. . . )
{
int rc ;
va_list ap ;
va_start ( ap , format ) ;
rc = xmlTextWriterWriteVFormatAttribute ( writer , name , format , ap ) ;
va_end ( ap ) ;
return rc ;
}
/**
* xmlTextWriterWriteVFormatAttribute :
* @ writer : the xmlTextWriterPtr
* @ name : attribute name
* @ format : format string ( see printf )
* @ argptr : pointer to the first member of the variable argument list .
*
* Write a formatted xml attribute .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterWriteVFormatAttribute ( xmlTextWriterPtr writer ,
const xmlChar * name ,
const char * format , va_list argptr )
{
int rc ;
xmlChar * buf ;
if ( writer = = NULL )
return - 1 ;
buf = xmlTextWriterVSprintf ( format , argptr ) ;
2009-02-20 11:40:55 +03:00
if ( buf = = NULL )
return - 1 ;
2003-10-21 02:32:39 +04:00
rc = xmlTextWriterWriteAttribute ( writer , name , buf ) ;
xmlFree ( buf ) ;
return rc ;
}
/**
* xmlTextWriterWriteAttribute :
* @ writer : the xmlTextWriterPtr
* @ name : attribute name
* @ content : attribute content
*
* Write an xml attribute .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterWriteAttribute ( xmlTextWriterPtr writer , const xmlChar * name ,
const xmlChar * content )
{
int count ;
int sum ;
sum = 0 ;
count = xmlTextWriterStartAttribute ( writer , name ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlTextWriterWriteString ( writer , content ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlTextWriterEndAttribute ( writer ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
return sum ;
}
/**
* xmlTextWriterWriteFormatAttributeNS :
* @ writer : the xmlTextWriterPtr
* @ prefix : namespace prefix
* @ name : attribute local name
* @ namespaceURI : namespace URI
* @ format : format string ( see printf )
2003-11-21 03:28:39 +03:00
* @ . . . : extra parameters for the format
2003-10-21 02:32:39 +04:00
*
* Write a formatted xml attribute . with namespace support
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2005-07-21 17:24:09 +04:00
int XMLCDECL
2003-10-21 02:32:39 +04:00
xmlTextWriterWriteFormatAttributeNS ( xmlTextWriterPtr writer ,
const xmlChar * prefix ,
const xmlChar * name ,
const xmlChar * namespaceURI ,
const char * format , . . . )
{
int rc ;
va_list ap ;
va_start ( ap , format ) ;
rc = xmlTextWriterWriteVFormatAttributeNS ( writer , prefix , name ,
namespaceURI , format , ap ) ;
va_end ( ap ) ;
return rc ;
}
/**
* xmlTextWriterWriteVFormatAttributeNS :
* @ writer : the xmlTextWriterPtr
* @ prefix : namespace prefix
* @ name : attribute local name
* @ namespaceURI : namespace URI
* @ format : format string ( see printf )
* @ argptr : pointer to the first member of the variable argument list .
*
* Write a formatted xml attribute . with namespace support
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterWriteVFormatAttributeNS ( xmlTextWriterPtr writer ,
const xmlChar * prefix ,
const xmlChar * name ,
const xmlChar * namespaceURI ,
const char * format , va_list argptr )
{
int rc ;
xmlChar * buf ;
if ( writer = = NULL )
return - 1 ;
buf = xmlTextWriterVSprintf ( format , argptr ) ;
2009-02-20 11:40:55 +03:00
if ( buf = = NULL )
return - 1 ;
2003-10-21 02:32:39 +04:00
rc = xmlTextWriterWriteAttributeNS ( writer , prefix , name , namespaceURI ,
buf ) ;
xmlFree ( buf ) ;
return rc ;
}
/**
* xmlTextWriterWriteAttributeNS :
* @ writer : the xmlTextWriterPtr
* @ prefix : namespace prefix
* @ name : attribute local name
* @ namespaceURI : namespace URI
* @ content : attribute content
*
* Write an xml attribute .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterWriteAttributeNS ( xmlTextWriterPtr writer ,
const xmlChar * prefix , const xmlChar * name ,
const xmlChar * namespaceURI ,
const xmlChar * content )
{
int count ;
int sum ;
if ( ( writer = = NULL ) | | ( name = = NULL ) | | ( * name = = ' \0 ' ) )
return - 1 ;
sum = 0 ;
2007-06-08 12:50:47 +04:00
count = xmlTextWriterStartAttributeNS ( writer , prefix , name , namespaceURI ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlTextWriterWriteString ( writer , content ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlTextWriterEndAttribute ( writer ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
return sum ;
}
/**
* xmlTextWriterWriteFormatElement :
* @ writer : the xmlTextWriterPtr
* @ name : element name
* @ format : format string ( see printf )
2003-11-21 03:28:39 +03:00
* @ . . . : extra parameters for the format
2003-10-21 02:32:39 +04:00
*
* Write a formatted xml element .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2005-07-21 17:24:09 +04:00
int XMLCDECL
2003-10-21 02:32:39 +04:00
xmlTextWriterWriteFormatElement ( xmlTextWriterPtr writer ,
const xmlChar * name , const char * format ,
. . . )
{
int rc ;
va_list ap ;
va_start ( ap , format ) ;
rc = xmlTextWriterWriteVFormatElement ( writer , name , format , ap ) ;
va_end ( ap ) ;
return rc ;
}
/**
* xmlTextWriterWriteVFormatElement :
* @ writer : the xmlTextWriterPtr
* @ name : element name
* @ format : format string ( see printf )
* @ argptr : pointer to the first member of the variable argument list .
*
* Write a formatted xml element .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterWriteVFormatElement ( xmlTextWriterPtr writer ,
const xmlChar * name , const char * format ,
va_list argptr )
{
int rc ;
xmlChar * buf ;
if ( writer = = NULL )
return - 1 ;
buf = xmlTextWriterVSprintf ( format , argptr ) ;
2009-02-20 11:40:55 +03:00
if ( buf = = NULL )
return - 1 ;
2003-10-21 02:32:39 +04:00
rc = xmlTextWriterWriteElement ( writer , name , buf ) ;
xmlFree ( buf ) ;
return rc ;
}
/**
* xmlTextWriterWriteElement :
* @ writer : the xmlTextWriterPtr
* @ name : element name
* @ content : element content
*
* Write an xml element .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterWriteElement ( xmlTextWriterPtr writer , const xmlChar * name ,
const xmlChar * content )
{
int count ;
int sum ;
sum = 0 ;
count = xmlTextWriterStartElement ( writer , name ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
2014-02-07 22:22:35 +04:00
if ( content ! = NULL ) {
count = xmlTextWriterWriteString ( writer , content ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
}
2003-10-21 02:32:39 +04:00
count = xmlTextWriterEndElement ( writer ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
return sum ;
}
/**
* xmlTextWriterWriteFormatElementNS :
* @ writer : the xmlTextWriterPtr
* @ prefix : namespace prefix
* @ name : element local name
* @ namespaceURI : namespace URI
* @ format : format string ( see printf )
2003-11-21 03:28:39 +03:00
* @ . . . : extra parameters for the format
2003-10-21 02:32:39 +04:00
*
* Write a formatted xml element with namespace support .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2005-07-21 17:24:09 +04:00
int XMLCDECL
2003-10-21 02:32:39 +04:00
xmlTextWriterWriteFormatElementNS ( xmlTextWriterPtr writer ,
const xmlChar * prefix ,
const xmlChar * name ,
const xmlChar * namespaceURI ,
const char * format , . . . )
{
int rc ;
va_list ap ;
va_start ( ap , format ) ;
rc = xmlTextWriterWriteVFormatElementNS ( writer , prefix , name ,
namespaceURI , format , ap ) ;
va_end ( ap ) ;
return rc ;
}
/**
* xmlTextWriterWriteVFormatElementNS :
* @ writer : the xmlTextWriterPtr
* @ prefix : namespace prefix
* @ name : element local name
* @ namespaceURI : namespace URI
* @ format : format string ( see printf )
* @ argptr : pointer to the first member of the variable argument list .
*
* Write a formatted xml element with namespace support .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterWriteVFormatElementNS ( xmlTextWriterPtr writer ,
const xmlChar * prefix ,
const xmlChar * name ,
const xmlChar * namespaceURI ,
const char * format , va_list argptr )
{
int rc ;
xmlChar * buf ;
if ( writer = = NULL )
return - 1 ;
buf = xmlTextWriterVSprintf ( format , argptr ) ;
2009-02-20 11:40:55 +03:00
if ( buf = = NULL )
return - 1 ;
2003-10-21 02:32:39 +04:00
rc = xmlTextWriterWriteElementNS ( writer , prefix , name , namespaceURI ,
buf ) ;
xmlFree ( buf ) ;
return rc ;
}
/**
* xmlTextWriterWriteElementNS :
* @ writer : the xmlTextWriterPtr
* @ prefix : namespace prefix
* @ name : element local name
* @ namespaceURI : namespace URI
* @ content : element content
*
* Write an xml element with namespace support .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterWriteElementNS ( xmlTextWriterPtr writer ,
const xmlChar * prefix , const xmlChar * name ,
const xmlChar * namespaceURI ,
const xmlChar * content )
{
int count ;
int sum ;
if ( ( writer = = NULL ) | | ( name = = NULL ) | | ( * name = = ' \0 ' ) )
return - 1 ;
sum = 0 ;
count =
xmlTextWriterStartElementNS ( writer , prefix , name , namespaceURI ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlTextWriterWriteString ( writer , content ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
count = xmlTextWriterEndElement ( writer ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
return sum ;
}
/**
* xmlTextWriterStartPI :
* @ writer : the xmlTextWriterPtr
* @ target : PI target
*
* Start an xml PI .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterStartPI ( xmlTextWriterPtr writer , const xmlChar * target )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
if ( ( writer = = NULL ) | | ( target = = NULL ) | | ( * target = = ' \0 ' ) )
return - 1 ;
if ( xmlStrcasecmp ( target , ( const xmlChar * ) " xml " ) = = 0 ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_INTERNAL_ERROR ,
2003-10-21 02:32:39 +04:00
" xmlTextWriterStartPI : target name [Xx][Mm][Ll] is reserved for xml standardization! \n " ) ;
return - 1 ;
}
sum = 0 ;
lk = xmlListFront ( writer - > nodes ) ;
if ( lk ! = 0 ) {
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
if ( p ! = 0 ) {
switch ( p - > state ) {
case XML_TEXTWRITER_ATTRIBUTE :
count = xmlTextWriterEndAttribute ( writer ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
/* fallthrough */
case XML_TEXTWRITER_NAME :
2007-06-08 12:50:47 +04:00
/* Output namespace declarations */
count = xmlTextWriterOutputNSDecl ( writer ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
2003-10-21 02:32:39 +04:00
count = xmlOutputBufferWriteString ( writer - > out , " > " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
p - > state = XML_TEXTWRITER_TEXT ;
break ;
2004-02-17 14:40:32 +03:00
case XML_TEXTWRITER_NONE :
case XML_TEXTWRITER_TEXT :
case XML_TEXTWRITER_DTD :
break ;
2003-10-21 02:32:39 +04:00
case XML_TEXTWRITER_PI :
case XML_TEXTWRITER_PI_TEXT :
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_INTERNAL_ERROR ,
2003-10-21 02:32:39 +04:00
" xmlTextWriterStartPI : nested PI! \n " ) ;
return - 1 ;
default :
return - 1 ;
}
}
}
p = ( xmlTextWriterStackEntry * )
xmlMalloc ( sizeof ( xmlTextWriterStackEntry ) ) ;
if ( p = = 0 ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_NO_MEMORY ,
2003-10-21 02:32:39 +04:00
" xmlTextWriterStartPI : out of memory! \n " ) ;
return - 1 ;
}
p - > name = xmlStrdup ( target ) ;
if ( p - > name = = 0 ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_NO_MEMORY ,
2003-10-21 02:32:39 +04:00
" xmlTextWriterStartPI : out of memory! \n " ) ;
xmlFree ( p ) ;
return - 1 ;
}
p - > state = XML_TEXTWRITER_PI ;
xmlListPushFront ( writer - > nodes , p ) ;
count = xmlOutputBufferWriteString ( writer - > out , " <? " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
2003-11-20 14:59:09 +03:00
count =
xmlOutputBufferWriteString ( writer - > out , ( const char * ) p - > name ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
return sum ;
}
/**
* xmlTextWriterEndPI :
* @ writer : the xmlTextWriterPtr
*
* End the current xml PI .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterEndPI ( xmlTextWriterPtr writer )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
if ( writer = = NULL )
return - 1 ;
lk = xmlListFront ( writer - > nodes ) ;
if ( lk = = 0 )
return 0 ;
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
if ( p = = 0 )
return 0 ;
sum = 0 ;
switch ( p - > state ) {
case XML_TEXTWRITER_PI :
case XML_TEXTWRITER_PI_TEXT :
count = xmlOutputBufferWriteString ( writer - > out , " ?> " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
break ;
default :
return - 1 ;
}
2006-04-27 12:10:25 +04:00
if ( writer - > indent ) {
count = xmlOutputBufferWriteString ( writer - > out , " \n " ) ;
2012-09-11 09:26:36 +04:00
if ( count < 0 )
return - 1 ;
2006-04-27 12:10:25 +04:00
sum + = count ;
}
2003-10-21 02:32:39 +04:00
xmlListPopFront ( writer - > nodes ) ;
return sum ;
}
/**
* xmlTextWriterWriteFormatPI :
* @ writer : the xmlTextWriterPtr
* @ target : PI target
* @ format : format string ( see printf )
2003-11-21 03:28:39 +03:00
* @ . . . : extra parameters for the format
2003-10-21 02:32:39 +04:00
*
* Write a formatted PI .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2005-07-21 17:24:09 +04:00
int XMLCDECL
2003-10-21 02:32:39 +04:00
xmlTextWriterWriteFormatPI ( xmlTextWriterPtr writer , const xmlChar * target ,
const char * format , . . . )
{
int rc ;
va_list ap ;
va_start ( ap , format ) ;
rc = xmlTextWriterWriteVFormatPI ( writer , target , format , ap ) ;
va_end ( ap ) ;
return rc ;
}
/**
* xmlTextWriterWriteVFormatPI :
* @ writer : the xmlTextWriterPtr
* @ target : PI target
* @ format : format string ( see printf )
2003-11-20 14:59:09 +03:00
* @ argptr : pointer to the first member of the variable argument list .
2003-10-21 02:32:39 +04:00
*
* Write a formatted xml PI .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterWriteVFormatPI ( xmlTextWriterPtr writer ,
const xmlChar * target , const char * format ,
va_list argptr )
{
int rc ;
xmlChar * buf ;
if ( writer = = NULL )
return - 1 ;
buf = xmlTextWriterVSprintf ( format , argptr ) ;
2009-02-20 11:40:55 +03:00
if ( buf = = NULL )
return - 1 ;
2003-10-21 02:32:39 +04:00
rc = xmlTextWriterWritePI ( writer , target , buf ) ;
xmlFree ( buf ) ;
return rc ;
}
/**
* xmlTextWriterWritePI :
* @ writer : the xmlTextWriterPtr
* @ target : PI target
* @ content : PI content
*
* Write an xml PI .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterWritePI ( xmlTextWriterPtr writer , const xmlChar * target ,
const xmlChar * content )
{
int count ;
int sum ;
sum = 0 ;
count = xmlTextWriterStartPI ( writer , target ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
if ( content ! = 0 ) {
count = xmlTextWriterWriteString ( writer , content ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
}
count = xmlTextWriterEndPI ( writer ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
return sum ;
}
/**
* xmlTextWriterStartCDATA :
* @ writer : the xmlTextWriterPtr
*
* Start an xml CDATA section .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterStartCDATA ( xmlTextWriterPtr writer )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
if ( writer = = NULL )
return - 1 ;
sum = 0 ;
lk = xmlListFront ( writer - > nodes ) ;
if ( lk ! = 0 ) {
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
if ( p ! = 0 ) {
switch ( p - > state ) {
case XML_TEXTWRITER_NONE :
2008-03-04 16:19:49 +03:00
case XML_TEXTWRITER_TEXT :
2003-10-21 02:32:39 +04:00
case XML_TEXTWRITER_PI :
case XML_TEXTWRITER_PI_TEXT :
break ;
case XML_TEXTWRITER_ATTRIBUTE :
count = xmlTextWriterEndAttribute ( writer ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
/* fallthrough */
case XML_TEXTWRITER_NAME :
2007-06-08 12:50:47 +04:00
/* Output namespace declarations */
count = xmlTextWriterOutputNSDecl ( writer ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
2003-10-21 02:32:39 +04:00
count = xmlOutputBufferWriteString ( writer - > out , " > " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
p - > state = XML_TEXTWRITER_TEXT ;
break ;
case XML_TEXTWRITER_CDATA :
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_INTERNAL_ERROR ,
2003-10-21 02:32:39 +04:00
" xmlTextWriterStartCDATA : CDATA not allowed in this context! \n " ) ;
return - 1 ;
default :
return - 1 ;
}
}
}
p = ( xmlTextWriterStackEntry * )
xmlMalloc ( sizeof ( xmlTextWriterStackEntry ) ) ;
if ( p = = 0 ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_NO_MEMORY ,
2003-10-21 02:32:39 +04:00
" xmlTextWriterStartCDATA : out of memory! \n " ) ;
return - 1 ;
}
2005-07-30 02:02:24 +04:00
p - > name = NULL ;
2003-10-21 02:32:39 +04:00
p - > state = XML_TEXTWRITER_CDATA ;
xmlListPushFront ( writer - > nodes , p ) ;
count = xmlOutputBufferWriteString ( writer - > out , " <![CDATA[ " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
return sum ;
}
/**
* xmlTextWriterEndCDATA :
* @ writer : the xmlTextWriterPtr
*
* End an xml CDATA section .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterEndCDATA ( xmlTextWriterPtr writer )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
if ( writer = = NULL )
return - 1 ;
lk = xmlListFront ( writer - > nodes ) ;
if ( lk = = 0 )
return - 1 ;
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
if ( p = = 0 )
return - 1 ;
sum = 0 ;
switch ( p - > state ) {
case XML_TEXTWRITER_CDATA :
count = xmlOutputBufferWriteString ( writer - > out , " ]]> " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
break ;
default :
return - 1 ;
}
xmlListPopFront ( writer - > nodes ) ;
return sum ;
}
/**
* xmlTextWriterWriteFormatCDATA :
* @ writer : the xmlTextWriterPtr
* @ format : format string ( see printf )
2003-11-21 03:28:39 +03:00
* @ . . . : extra parameters for the format
2003-10-21 02:32:39 +04:00
*
* Write a formatted xml CDATA .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2005-07-21 17:24:09 +04:00
int XMLCDECL
2003-10-21 02:32:39 +04:00
xmlTextWriterWriteFormatCDATA ( xmlTextWriterPtr writer , const char * format ,
. . . )
{
int rc ;
va_list ap ;
va_start ( ap , format ) ;
rc = xmlTextWriterWriteVFormatCDATA ( writer , format , ap ) ;
va_end ( ap ) ;
return rc ;
}
/**
* xmlTextWriterWriteVFormatCDATA :
* @ writer : the xmlTextWriterPtr
* @ format : format string ( see printf )
2003-11-20 14:59:09 +03:00
* @ argptr : pointer to the first member of the variable argument list .
2003-10-21 02:32:39 +04:00
*
* Write a formatted xml CDATA .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterWriteVFormatCDATA ( xmlTextWriterPtr writer , const char * format ,
va_list argptr )
{
int rc ;
xmlChar * buf ;
if ( writer = = NULL )
return - 1 ;
buf = xmlTextWriterVSprintf ( format , argptr ) ;
2009-02-20 11:40:55 +03:00
if ( buf = = NULL )
return - 1 ;
2003-10-21 02:32:39 +04:00
rc = xmlTextWriterWriteCDATA ( writer , buf ) ;
xmlFree ( buf ) ;
return rc ;
}
/**
* xmlTextWriterWriteCDATA :
* @ writer : the xmlTextWriterPtr
* @ content : CDATA content
*
* Write an xml CDATA .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterWriteCDATA ( xmlTextWriterPtr writer , const xmlChar * content )
{
int count ;
int sum ;
sum = 0 ;
count = xmlTextWriterStartCDATA ( writer ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
if ( content ! = 0 ) {
count = xmlTextWriterWriteString ( writer , content ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
}
count = xmlTextWriterEndCDATA ( writer ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
return sum ;
}
/**
* xmlTextWriterStartDTD :
* @ writer : the xmlTextWriterPtr
* @ name : the name of the DTD
* @ pubid : the public identifier , which is an alternative to the system identifier
* @ sysid : the system identifier , which is the URI of the DTD
*
* Start an xml DTD .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterStartDTD ( xmlTextWriterPtr writer ,
const xmlChar * name ,
const xmlChar * pubid , const xmlChar * sysid )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
if ( writer = = NULL | | name = = NULL | | * name = = ' \0 ' )
return - 1 ;
sum = 0 ;
lk = xmlListFront ( writer - > nodes ) ;
2004-02-17 14:40:32 +03:00
if ( ( lk ! = NULL ) & & ( xmlLinkGetData ( lk ) ! = NULL ) ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_INTERNAL_ERROR ,
2003-10-21 02:32:39 +04:00
" xmlTextWriterStartDTD : DTD allowed only in prolog! \n " ) ;
return - 1 ;
}
p = ( xmlTextWriterStackEntry * )
xmlMalloc ( sizeof ( xmlTextWriterStackEntry ) ) ;
if ( p = = 0 ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_NO_MEMORY ,
2003-10-21 02:32:39 +04:00
" xmlTextWriterStartDTD : out of memory! \n " ) ;
return - 1 ;
}
p - > name = xmlStrdup ( name ) ;
if ( p - > name = = 0 ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_NO_MEMORY ,
2003-10-21 02:32:39 +04:00
" xmlTextWriterStartDTD : out of memory! \n " ) ;
xmlFree ( p ) ;
return - 1 ;
}
p - > state = XML_TEXTWRITER_DTD ;
xmlListPushFront ( writer - > nodes , p ) ;
count = xmlOutputBufferWriteString ( writer - > out , " <!DOCTYPE " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWriteString ( writer - > out , ( const char * ) name ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
if ( pubid ! = 0 ) {
if ( sysid = = 0 ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_INTERNAL_ERROR ,
2003-10-21 02:32:39 +04:00
" xmlTextWriterStartDTD : system identifier needed! \n " ) ;
return - 1 ;
}
2004-03-22 18:22:58 +03:00
if ( writer - > indent )
count = xmlOutputBufferWrite ( writer - > out , 1 , " \n " ) ;
else
count = xmlOutputBufferWrite ( writer - > out , 1 , " " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWriteString ( writer - > out , " PUBLIC " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWrite ( writer - > out , 1 , & writer - > qchar ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
2003-11-20 14:59:09 +03:00
count =
xmlOutputBufferWriteString ( writer - > out , ( const char * ) pubid ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
2004-03-22 18:22:58 +03:00
count = xmlOutputBufferWrite ( writer - > out , 1 , & writer - > qchar ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
}
if ( sysid ! = 0 ) {
if ( pubid = = 0 ) {
2004-03-22 18:22:58 +03:00
if ( writer - > indent )
count = xmlOutputBufferWrite ( writer - > out , 1 , " \n " ) ;
else
count = xmlOutputBufferWrite ( writer - > out , 1 , " " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWriteString ( writer - > out , " SYSTEM " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
2005-12-09 20:52:21 +03:00
} else {
if ( writer - > indent )
2004-03-22 18:22:58 +03:00
count = xmlOutputBufferWriteString ( writer - > out , " \n " ) ;
2005-12-09 20:52:21 +03:00
else
count = xmlOutputBufferWrite ( writer - > out , 1 , " " ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
}
2004-03-22 18:22:58 +03:00
count = xmlOutputBufferWrite ( writer - > out , 1 , & writer - > qchar ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
2003-11-20 14:59:09 +03:00
count =
xmlOutputBufferWriteString ( writer - > out , ( const char * ) sysid ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
2004-03-22 18:22:58 +03:00
count = xmlOutputBufferWrite ( writer - > out , 1 , & writer - > qchar ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
}
return sum ;
}
/**
* xmlTextWriterEndDTD :
* @ writer : the xmlTextWriterPtr
*
* End an xml DTD .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterEndDTD ( xmlTextWriterPtr writer )
{
2004-03-22 18:22:58 +03:00
int loop ;
2003-10-21 02:32:39 +04:00
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
if ( writer = = NULL )
return - 1 ;
sum = 0 ;
2004-03-22 18:22:58 +03:00
loop = 1 ;
while ( loop ) {
lk = xmlListFront ( writer - > nodes ) ;
if ( lk = = NULL )
break ;
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
if ( p = = 0 )
break ;
switch ( p - > state ) {
case XML_TEXTWRITER_DTD_TEXT :
count = xmlOutputBufferWriteString ( writer - > out , " ] " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
/* fallthrough */
case XML_TEXTWRITER_DTD :
count = xmlOutputBufferWriteString ( writer - > out , " > " ) ;
2003-10-21 02:32:39 +04:00
2004-03-22 18:22:58 +03:00
if ( writer - > indent ) {
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWriteString ( writer - > out , " \n " ) ;
}
2003-10-21 02:32:39 +04:00
2004-03-22 18:22:58 +03:00
xmlListPopFront ( writer - > nodes ) ;
break ;
case XML_TEXTWRITER_DTD_ELEM :
case XML_TEXTWRITER_DTD_ELEM_TEXT :
count = xmlTextWriterEndDTDElement ( writer ) ;
break ;
case XML_TEXTWRITER_DTD_ATTL :
case XML_TEXTWRITER_DTD_ATTL_TEXT :
count = xmlTextWriterEndDTDAttlist ( writer ) ;
break ;
case XML_TEXTWRITER_DTD_ENTY :
case XML_TEXTWRITER_DTD_PENT :
case XML_TEXTWRITER_DTD_ENTY_TEXT :
count = xmlTextWriterEndDTDEntity ( writer ) ;
break ;
case XML_TEXTWRITER_COMMENT :
count = xmlTextWriterEndComment ( writer ) ;
break ;
default :
loop = 0 ;
continue ;
}
if ( count < 0 )
2003-10-21 02:32:39 +04:00
return - 1 ;
2004-03-22 18:22:58 +03:00
sum + = count ;
2003-10-21 02:32:39 +04:00
}
return sum ;
}
/**
* xmlTextWriterWriteFormatDTD :
* @ writer : the xmlTextWriterPtr
* @ name : the name of the DTD
* @ pubid : the public identifier , which is an alternative to the system identifier
* @ sysid : the system identifier , which is the URI of the DTD
* @ format : format string ( see printf )
2003-11-21 03:28:39 +03:00
* @ . . . : extra parameters for the format
2003-10-21 02:32:39 +04:00
*
* Write a DTD with a formatted markup declarations part .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2005-07-21 17:24:09 +04:00
int XMLCDECL
2003-10-21 02:32:39 +04:00
xmlTextWriterWriteFormatDTD ( xmlTextWriterPtr writer ,
const xmlChar * name ,
const xmlChar * pubid ,
const xmlChar * sysid , const char * format , . . . )
{
int rc ;
va_list ap ;
va_start ( ap , format ) ;
rc = xmlTextWriterWriteVFormatDTD ( writer , name , pubid , sysid , format ,
ap ) ;
va_end ( ap ) ;
return rc ;
}
/**
* xmlTextWriterWriteVFormatDTD :
* @ writer : the xmlTextWriterPtr
* @ name : the name of the DTD
* @ pubid : the public identifier , which is an alternative to the system identifier
* @ sysid : the system identifier , which is the URI of the DTD
* @ format : format string ( see printf )
2003-11-20 14:59:09 +03:00
* @ argptr : pointer to the first member of the variable argument list .
2003-10-21 02:32:39 +04:00
*
* Write a DTD with a formatted markup declarations part .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterWriteVFormatDTD ( xmlTextWriterPtr writer ,
const xmlChar * name ,
const xmlChar * pubid ,
const xmlChar * sysid ,
const char * format , va_list argptr )
{
int rc ;
xmlChar * buf ;
if ( writer = = NULL )
return - 1 ;
buf = xmlTextWriterVSprintf ( format , argptr ) ;
2009-02-20 11:40:55 +03:00
if ( buf = = NULL )
return - 1 ;
2003-10-21 02:32:39 +04:00
rc = xmlTextWriterWriteDTD ( writer , name , pubid , sysid , buf ) ;
xmlFree ( buf ) ;
return rc ;
}
/**
* xmlTextWriterWriteDTD :
* @ writer : the xmlTextWriterPtr
* @ name : the name of the DTD
* @ pubid : the public identifier , which is an alternative to the system identifier
* @ sysid : the system identifier , which is the URI of the DTD
2003-11-18 09:54:40 +03:00
* @ subset : string content of the DTD
2003-10-21 02:32:39 +04:00
*
* Write a DTD .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterWriteDTD ( xmlTextWriterPtr writer ,
const xmlChar * name ,
const xmlChar * pubid ,
const xmlChar * sysid , const xmlChar * subset )
{
int count ;
int sum ;
sum = 0 ;
count = xmlTextWriterStartDTD ( writer , name , pubid , sysid ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
if ( subset ! = 0 ) {
count = xmlTextWriterWriteString ( writer , subset ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
}
count = xmlTextWriterEndDTD ( writer ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
return sum ;
}
2003-11-20 14:59:09 +03:00
/**
* xmlTextWriterStartDTDElement :
* @ writer : the xmlTextWriterPtr
* @ name : the name of the DTD element
*
* Start an xml DTD element .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2003-10-21 02:32:39 +04:00
int
xmlTextWriterStartDTDElement ( xmlTextWriterPtr writer , const xmlChar * name )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
if ( writer = = NULL | | name = = NULL | | * name = = ' \0 ' )
return - 1 ;
sum = 0 ;
lk = xmlListFront ( writer - > nodes ) ;
if ( lk = = 0 ) {
return - 1 ;
}
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
2004-03-22 18:22:58 +03:00
if ( p ! = 0 ) {
switch ( p - > state ) {
case XML_TEXTWRITER_DTD :
count = xmlOutputBufferWriteString ( writer - > out , " [ " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
if ( writer - > indent ) {
count = xmlOutputBufferWriteString ( writer - > out , " \n " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
}
p - > state = XML_TEXTWRITER_DTD_TEXT ;
/* fallthrough */
case XML_TEXTWRITER_DTD_TEXT :
case XML_TEXTWRITER_NONE :
break ;
default :
2003-10-21 02:32:39 +04:00
return - 1 ;
2004-03-22 18:22:58 +03:00
}
2003-10-21 02:32:39 +04:00
}
p = ( xmlTextWriterStackEntry * )
xmlMalloc ( sizeof ( xmlTextWriterStackEntry ) ) ;
if ( p = = 0 ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_NO_MEMORY ,
2003-10-21 02:32:39 +04:00
" xmlTextWriterStartDTDElement : out of memory! \n " ) ;
return - 1 ;
}
p - > name = xmlStrdup ( name ) ;
if ( p - > name = = 0 ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_NO_MEMORY ,
2003-10-21 02:32:39 +04:00
" xmlTextWriterStartDTDElement : out of memory! \n " ) ;
xmlFree ( p ) ;
return - 1 ;
}
p - > state = XML_TEXTWRITER_DTD_ELEM ;
xmlListPushFront ( writer - > nodes , p ) ;
2004-03-22 18:22:58 +03:00
if ( writer - > indent ) {
count = xmlTextWriterWriteIndent ( writer ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
}
2003-10-21 02:32:39 +04:00
count = xmlOutputBufferWriteString ( writer - > out , " <!ELEMENT " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWriteString ( writer - > out , ( const char * ) name ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
return sum ;
}
2004-03-22 18:22:58 +03:00
/**
* xmlTextWriterEndDTDElement :
* @ writer : the xmlTextWriterPtr
*
* End an xml DTD element .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterEndDTDElement ( xmlTextWriterPtr writer )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
if ( writer = = NULL )
return - 1 ;
sum = 0 ;
lk = xmlListFront ( writer - > nodes ) ;
if ( lk = = 0 )
return - 1 ;
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
if ( p = = 0 )
return - 1 ;
switch ( p - > state ) {
case XML_TEXTWRITER_DTD_ELEM :
case XML_TEXTWRITER_DTD_ELEM_TEXT :
count = xmlOutputBufferWriteString ( writer - > out , " > " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
break ;
default :
return - 1 ;
}
if ( writer - > indent ) {
count = xmlOutputBufferWriteString ( writer - > out , " \n " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
}
xmlListPopFront ( writer - > nodes ) ;
return sum ;
}
2003-11-20 14:59:09 +03:00
/**
* xmlTextWriterWriteFormatDTDElement :
* @ writer : the xmlTextWriterPtr
* @ name : the name of the DTD element
* @ format : format string ( see printf )
2003-11-21 03:28:39 +03:00
* @ . . . : extra parameters for the format
2003-11-20 14:59:09 +03:00
*
* Write a formatted DTD element .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2005-07-21 17:24:09 +04:00
int XMLCDECL
2003-10-21 02:32:39 +04:00
xmlTextWriterWriteFormatDTDElement ( xmlTextWriterPtr writer ,
const xmlChar * name ,
const char * format , . . . )
{
int rc ;
va_list ap ;
va_start ( ap , format ) ;
rc = xmlTextWriterWriteVFormatDTDElement ( writer , name , format , ap ) ;
va_end ( ap ) ;
return rc ;
}
2003-11-20 14:59:09 +03:00
/**
* xmlTextWriterWriteVFormatDTDElement :
* @ writer : the xmlTextWriterPtr
* @ name : the name of the DTD element
* @ format : format string ( see printf )
* @ argptr : pointer to the first member of the variable argument list .
*
* Write a formatted DTD element .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2003-10-21 02:32:39 +04:00
int
xmlTextWriterWriteVFormatDTDElement ( xmlTextWriterPtr writer ,
const xmlChar * name ,
const char * format , va_list argptr )
{
int rc ;
xmlChar * buf ;
if ( writer = = NULL )
return - 1 ;
buf = xmlTextWriterVSprintf ( format , argptr ) ;
2009-02-20 11:40:55 +03:00
if ( buf = = NULL )
return - 1 ;
2003-10-21 02:32:39 +04:00
rc = xmlTextWriterWriteDTDElement ( writer , name , buf ) ;
xmlFree ( buf ) ;
return rc ;
}
2003-11-20 14:59:09 +03:00
/**
* xmlTextWriterWriteDTDElement :
* @ writer : the xmlTextWriterPtr
* @ name : the name of the DTD element
* @ content : content of the element
*
* Write a DTD element .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2003-10-21 02:32:39 +04:00
int
xmlTextWriterWriteDTDElement ( xmlTextWriterPtr writer ,
const xmlChar * name , const xmlChar * content )
{
int count ;
int sum ;
if ( content = = NULL )
return - 1 ;
sum = 0 ;
count = xmlTextWriterStartDTDElement ( writer , name ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
count = xmlTextWriterWriteString ( writer , content ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
count = xmlTextWriterEndDTDElement ( writer ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
return sum ;
}
2003-11-20 14:59:09 +03:00
/**
* xmlTextWriterStartDTDAttlist :
* @ writer : the xmlTextWriterPtr
* @ name : the name of the DTD ATTLIST
*
* Start an xml DTD ATTLIST .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2003-10-21 02:32:39 +04:00
int
xmlTextWriterStartDTDAttlist ( xmlTextWriterPtr writer , const xmlChar * name )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
if ( writer = = NULL | | name = = NULL | | * name = = ' \0 ' )
return - 1 ;
sum = 0 ;
lk = xmlListFront ( writer - > nodes ) ;
if ( lk = = 0 ) {
return - 1 ;
}
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
2004-03-22 18:22:58 +03:00
if ( p ! = 0 ) {
switch ( p - > state ) {
case XML_TEXTWRITER_DTD :
count = xmlOutputBufferWriteString ( writer - > out , " [ " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
if ( writer - > indent ) {
count = xmlOutputBufferWriteString ( writer - > out , " \n " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
}
p - > state = XML_TEXTWRITER_DTD_TEXT ;
/* fallthrough */
case XML_TEXTWRITER_DTD_TEXT :
case XML_TEXTWRITER_NONE :
break ;
default :
2003-10-21 02:32:39 +04:00
return - 1 ;
2004-03-22 18:22:58 +03:00
}
2003-10-21 02:32:39 +04:00
}
p = ( xmlTextWriterStackEntry * )
xmlMalloc ( sizeof ( xmlTextWriterStackEntry ) ) ;
if ( p = = 0 ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_NO_MEMORY ,
2003-10-21 02:32:39 +04:00
" xmlTextWriterStartDTDAttlist : out of memory! \n " ) ;
return - 1 ;
}
p - > name = xmlStrdup ( name ) ;
if ( p - > name = = 0 ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_NO_MEMORY ,
2003-10-21 02:32:39 +04:00
" xmlTextWriterStartDTDAttlist : out of memory! \n " ) ;
xmlFree ( p ) ;
return - 1 ;
}
p - > state = XML_TEXTWRITER_DTD_ATTL ;
xmlListPushFront ( writer - > nodes , p ) ;
2004-03-22 18:22:58 +03:00
if ( writer - > indent ) {
count = xmlTextWriterWriteIndent ( writer ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
}
2003-10-21 02:32:39 +04:00
count = xmlOutputBufferWriteString ( writer - > out , " <!ATTLIST " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
2004-02-17 14:40:32 +03:00
count = xmlOutputBufferWriteString ( writer - > out , ( const char * ) name ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
return sum ;
}
2004-03-22 18:22:58 +03:00
/**
* xmlTextWriterEndDTDAttlist :
* @ writer : the xmlTextWriterPtr
*
* End an xml DTD attribute list .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterEndDTDAttlist ( xmlTextWriterPtr writer )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
if ( writer = = NULL )
return - 1 ;
sum = 0 ;
lk = xmlListFront ( writer - > nodes ) ;
if ( lk = = 0 )
return - 1 ;
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
if ( p = = 0 )
return - 1 ;
switch ( p - > state ) {
case XML_TEXTWRITER_DTD_ATTL :
case XML_TEXTWRITER_DTD_ATTL_TEXT :
count = xmlOutputBufferWriteString ( writer - > out , " > " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
break ;
default :
return - 1 ;
}
if ( writer - > indent ) {
count = xmlOutputBufferWriteString ( writer - > out , " \n " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
}
xmlListPopFront ( writer - > nodes ) ;
return sum ;
}
2003-11-20 14:59:09 +03:00
/**
* xmlTextWriterWriteFormatDTDAttlist :
* @ writer : the xmlTextWriterPtr
* @ name : the name of the DTD ATTLIST
* @ format : format string ( see printf )
2003-11-21 03:28:39 +03:00
* @ . . . : extra parameters for the format
2003-11-20 14:59:09 +03:00
*
* Write a formatted DTD ATTLIST .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2005-07-21 17:24:09 +04:00
int XMLCDECL
2003-10-21 02:32:39 +04:00
xmlTextWriterWriteFormatDTDAttlist ( xmlTextWriterPtr writer ,
const xmlChar * name ,
const char * format , . . . )
{
int rc ;
va_list ap ;
va_start ( ap , format ) ;
rc = xmlTextWriterWriteVFormatDTDAttlist ( writer , name , format , ap ) ;
va_end ( ap ) ;
return rc ;
}
2003-11-20 14:59:09 +03:00
/**
* xmlTextWriterWriteVFormatDTDAttlist :
* @ writer : the xmlTextWriterPtr
* @ name : the name of the DTD ATTLIST
* @ format : format string ( see printf )
* @ argptr : pointer to the first member of the variable argument list .
*
* Write a formatted DTD ATTLIST .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2003-10-21 02:32:39 +04:00
int
xmlTextWriterWriteVFormatDTDAttlist ( xmlTextWriterPtr writer ,
const xmlChar * name ,
const char * format , va_list argptr )
{
int rc ;
xmlChar * buf ;
if ( writer = = NULL )
return - 1 ;
buf = xmlTextWriterVSprintf ( format , argptr ) ;
2009-02-20 11:40:55 +03:00
if ( buf = = NULL )
return - 1 ;
2003-10-21 02:32:39 +04:00
rc = xmlTextWriterWriteDTDAttlist ( writer , name , buf ) ;
xmlFree ( buf ) ;
return rc ;
}
2003-11-20 14:59:09 +03:00
/**
* xmlTextWriterWriteDTDAttlist :
* @ writer : the xmlTextWriterPtr
* @ name : the name of the DTD ATTLIST
* @ content : content of the ATTLIST
*
* Write a DTD ATTLIST .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2003-10-21 02:32:39 +04:00
int
xmlTextWriterWriteDTDAttlist ( xmlTextWriterPtr writer ,
const xmlChar * name , const xmlChar * content )
{
int count ;
int sum ;
if ( content = = NULL )
return - 1 ;
sum = 0 ;
count = xmlTextWriterStartDTDAttlist ( writer , name ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
count = xmlTextWriterWriteString ( writer , content ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
count = xmlTextWriterEndDTDAttlist ( writer ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
return sum ;
}
2003-11-20 14:59:09 +03:00
/**
* xmlTextWriterStartDTDEntity :
* @ writer : the xmlTextWriterPtr
* @ pe : TRUE if this is a parameter entity , FALSE if not
* @ name : the name of the DTD ATTLIST
*
* Start an xml DTD ATTLIST .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2003-10-21 02:32:39 +04:00
int
xmlTextWriterStartDTDEntity ( xmlTextWriterPtr writer ,
int pe , const xmlChar * name )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
if ( writer = = NULL | | name = = NULL | | * name = = ' \0 ' )
return - 1 ;
sum = 0 ;
lk = xmlListFront ( writer - > nodes ) ;
2004-03-22 18:22:58 +03:00
if ( lk ! = 0 ) {
2003-10-21 02:32:39 +04:00
2004-03-22 18:22:58 +03:00
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
if ( p ! = 0 ) {
switch ( p - > state ) {
case XML_TEXTWRITER_DTD :
count = xmlOutputBufferWriteString ( writer - > out , " [ " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
if ( writer - > indent ) {
count =
xmlOutputBufferWriteString ( writer - > out , " \n " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
}
p - > state = XML_TEXTWRITER_DTD_TEXT ;
/* fallthrough */
case XML_TEXTWRITER_DTD_TEXT :
case XML_TEXTWRITER_NONE :
break ;
default :
return - 1 ;
}
}
2003-10-21 02:32:39 +04:00
}
p = ( xmlTextWriterStackEntry * )
xmlMalloc ( sizeof ( xmlTextWriterStackEntry ) ) ;
if ( p = = 0 ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_NO_MEMORY ,
2003-10-21 02:32:39 +04:00
" xmlTextWriterStartDTDElement : out of memory! \n " ) ;
return - 1 ;
}
p - > name = xmlStrdup ( name ) ;
if ( p - > name = = 0 ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_NO_MEMORY ,
2003-10-21 02:32:39 +04:00
" xmlTextWriterStartDTDElement : out of memory! \n " ) ;
xmlFree ( p ) ;
return - 1 ;
}
2004-03-22 18:22:58 +03:00
if ( pe ! = 0 )
p - > state = XML_TEXTWRITER_DTD_PENT ;
else
p - > state = XML_TEXTWRITER_DTD_ENTY ;
2003-10-21 02:32:39 +04:00
xmlListPushFront ( writer - > nodes , p ) ;
2004-03-22 18:22:58 +03:00
if ( writer - > indent ) {
count = xmlTextWriterWriteIndent ( writer ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
}
2003-10-21 02:32:39 +04:00
count = xmlOutputBufferWriteString ( writer - > out , " <!ENTITY " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
if ( pe ! = 0 ) {
2004-03-22 18:22:58 +03:00
count = xmlOutputBufferWriteString ( writer - > out , " % " ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
}
2004-02-17 14:40:32 +03:00
count = xmlOutputBufferWriteString ( writer - > out , ( const char * ) name ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
return sum ;
}
2004-03-22 18:22:58 +03:00
/**
* xmlTextWriterEndDTDEntity :
* @ writer : the xmlTextWriterPtr
*
* End an xml DTD entity .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterEndDTDEntity ( xmlTextWriterPtr writer )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
if ( writer = = NULL )
return - 1 ;
sum = 0 ;
lk = xmlListFront ( writer - > nodes ) ;
if ( lk = = 0 )
return - 1 ;
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
if ( p = = 0 )
return - 1 ;
switch ( p - > state ) {
case XML_TEXTWRITER_DTD_ENTY_TEXT :
count = xmlOutputBufferWrite ( writer - > out , 1 , & writer - > qchar ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
2017-10-21 14:49:31 +03:00
/* Falls through. */
2004-03-22 18:22:58 +03:00
case XML_TEXTWRITER_DTD_ENTY :
case XML_TEXTWRITER_DTD_PENT :
count = xmlOutputBufferWriteString ( writer - > out , " > " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
break ;
default :
return - 1 ;
}
if ( writer - > indent ) {
count = xmlOutputBufferWriteString ( writer - > out , " \n " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
}
xmlListPopFront ( writer - > nodes ) ;
return sum ;
}
2003-11-20 14:59:09 +03:00
/**
* xmlTextWriterWriteFormatDTDInternalEntity :
* @ writer : the xmlTextWriterPtr
* @ pe : TRUE if this is a parameter entity , FALSE if not
* @ name : the name of the DTD entity
* @ format : format string ( see printf )
2003-11-21 03:28:39 +03:00
* @ . . . : extra parameters for the format
2003-11-20 14:59:09 +03:00
*
* Write a formatted DTD internal entity .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2005-07-21 17:24:09 +04:00
int XMLCDECL
2003-10-21 02:32:39 +04:00
xmlTextWriterWriteFormatDTDInternalEntity ( xmlTextWriterPtr writer ,
int pe ,
const xmlChar * name ,
const char * format , . . . )
{
int rc ;
va_list ap ;
va_start ( ap , format ) ;
rc = xmlTextWriterWriteVFormatDTDInternalEntity ( writer , pe , name ,
format , ap ) ;
va_end ( ap ) ;
return rc ;
}
2003-11-20 14:59:09 +03:00
/**
* xmlTextWriterWriteVFormatDTDInternalEntity :
* @ writer : the xmlTextWriterPtr
* @ pe : TRUE if this is a parameter entity , FALSE if not
* @ name : the name of the DTD entity
* @ format : format string ( see printf )
* @ argptr : pointer to the first member of the variable argument list .
*
* Write a formatted DTD internal entity .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2003-10-21 02:32:39 +04:00
int
xmlTextWriterWriteVFormatDTDInternalEntity ( xmlTextWriterPtr writer ,
int pe ,
const xmlChar * name ,
const char * format ,
va_list argptr )
{
int rc ;
xmlChar * buf ;
if ( writer = = NULL )
return - 1 ;
buf = xmlTextWriterVSprintf ( format , argptr ) ;
2009-02-20 11:40:55 +03:00
if ( buf = = NULL )
return - 1 ;
2003-10-21 02:32:39 +04:00
rc = xmlTextWriterWriteDTDInternalEntity ( writer , pe , name , buf ) ;
xmlFree ( buf ) ;
return rc ;
}
2003-11-20 14:59:09 +03:00
/**
* xmlTextWriterWriteDTDEntity :
* @ writer : the xmlTextWriterPtr
* @ pe : TRUE if this is a parameter entity , FALSE if not
* @ name : the name of the DTD entity
* @ pubid : the public identifier , which is an alternative to the system identifier
* @ sysid : the system identifier , which is the URI of the DTD
* @ ndataid : the xml notation name .
* @ content : content of the entity
*
* Write a DTD entity .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2003-10-21 02:32:39 +04:00
int
xmlTextWriterWriteDTDEntity ( xmlTextWriterPtr writer ,
int pe ,
const xmlChar * name ,
const xmlChar * pubid ,
const xmlChar * sysid ,
const xmlChar * ndataid ,
const xmlChar * content )
{
2004-03-22 18:22:58 +03:00
if ( ( content = = NULL ) & & ( pubid = = NULL ) & & ( sysid = = NULL ) )
2003-10-21 02:32:39 +04:00
return - 1 ;
if ( ( pe ! = 0 ) & & ( ndataid ! = NULL ) )
return - 1 ;
2004-03-22 18:22:58 +03:00
if ( ( pubid = = NULL ) & & ( sysid = = NULL ) )
2003-10-21 02:32:39 +04:00
return xmlTextWriterWriteDTDInternalEntity ( writer , pe , name ,
content ) ;
return xmlTextWriterWriteDTDExternalEntity ( writer , pe , name , pubid ,
sysid , ndataid ) ;
}
2003-11-20 14:59:09 +03:00
/**
* xmlTextWriterWriteDTDInternalEntity :
* @ writer : the xmlTextWriterPtr
* @ pe : TRUE if this is a parameter entity , FALSE if not
* @ name : the name of the DTD entity
* @ content : content of the entity
*
* Write a DTD internal entity .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2003-10-21 02:32:39 +04:00
int
xmlTextWriterWriteDTDInternalEntity ( xmlTextWriterPtr writer ,
int pe ,
const xmlChar * name ,
const xmlChar * content )
{
int count ;
int sum ;
if ( ( name = = NULL ) | | ( * name = = ' \0 ' ) | | ( content = = NULL ) )
return - 1 ;
sum = 0 ;
count = xmlTextWriterStartDTDEntity ( writer , pe , name ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
count = xmlTextWriterWriteString ( writer , content ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
count = xmlTextWriterEndDTDEntity ( writer ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
return sum ;
}
2003-11-20 14:59:09 +03:00
/**
* xmlTextWriterWriteDTDExternalEntity :
* @ writer : the xmlTextWriterPtr
* @ pe : TRUE if this is a parameter entity , FALSE if not
* @ name : the name of the DTD entity
* @ pubid : the public identifier , which is an alternative to the system identifier
* @ sysid : the system identifier , which is the URI of the DTD
* @ ndataid : the xml notation name .
*
2004-03-22 18:22:58 +03:00
* Write a DTD external entity . The entity must have been started with xmlTextWriterStartDTDEntity
2003-11-20 14:59:09 +03:00
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2003-10-21 02:32:39 +04:00
int
xmlTextWriterWriteDTDExternalEntity ( xmlTextWriterPtr writer ,
int pe ,
const xmlChar * name ,
const xmlChar * pubid ,
const xmlChar * sysid ,
const xmlChar * ndataid )
{
int count ;
int sum ;
2004-03-22 18:22:58 +03:00
if ( ( ( pubid = = NULL ) & & ( sysid = = NULL ) ) )
2003-10-21 02:32:39 +04:00
return - 1 ;
if ( ( pe ! = 0 ) & & ( ndataid ! = NULL ) )
return - 1 ;
sum = 0 ;
count = xmlTextWriterStartDTDEntity ( writer , pe , name ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
2004-03-22 18:22:58 +03:00
count =
xmlTextWriterWriteDTDExternalEntityContents ( writer , pubid , sysid ,
ndataid ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlTextWriterEndDTDEntity ( writer ) ;
if ( count = = - 1 )
return - 1 ;
sum + = count ;
return sum ;
}
/**
* xmlTextWriterWriteDTDExternalEntityContents :
* @ writer : the xmlTextWriterPtr
* @ pubid : the public identifier , which is an alternative to the system identifier
* @ sysid : the system identifier , which is the URI of the DTD
* @ ndataid : the xml notation name .
*
* Write the contents of a DTD external entity .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterWriteDTDExternalEntityContents ( xmlTextWriterPtr writer ,
const xmlChar * pubid ,
const xmlChar * sysid ,
const xmlChar * ndataid )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
if ( writer = = NULL ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_INTERNAL_ERROR ,
2004-03-22 18:22:58 +03:00
" xmlTextWriterWriteDTDExternalEntityContents: xmlTextWriterPtr invalid! \n " ) ;
return - 1 ;
}
sum = 0 ;
lk = xmlListFront ( writer - > nodes ) ;
if ( lk = = 0 ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_INTERNAL_ERROR ,
2004-03-22 18:22:58 +03:00
" xmlTextWriterWriteDTDExternalEntityContents: you must call xmlTextWriterStartDTDEntity before the call to this function! \n " ) ;
return - 1 ;
}
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
if ( p = = 0 )
return - 1 ;
switch ( p - > state ) {
case XML_TEXTWRITER_DTD_ENTY :
break ;
case XML_TEXTWRITER_DTD_PENT :
if ( ndataid ! = NULL ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_INTERNAL_ERROR ,
2004-03-22 18:22:58 +03:00
" xmlTextWriterWriteDTDExternalEntityContents: notation not allowed with parameter entities! \n " ) ;
return - 1 ;
}
break ;
default :
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_INTERNAL_ERROR ,
2004-03-22 18:22:58 +03:00
" xmlTextWriterWriteDTDExternalEntityContents: you must call xmlTextWriterStartDTDEntity before the call to this function! \n " ) ;
return - 1 ;
}
2003-10-21 02:32:39 +04:00
if ( pubid ! = 0 ) {
if ( sysid = = 0 ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( writer , XML_ERR_INTERNAL_ERROR ,
2004-03-22 18:22:58 +03:00
" xmlTextWriterWriteDTDExternalEntityContents: system identifier needed! \n " ) ;
2003-10-21 02:32:39 +04:00
return - 1 ;
}
count = xmlOutputBufferWriteString ( writer - > out , " PUBLIC " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWrite ( writer - > out , 1 , & writer - > qchar ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
2003-11-20 14:59:09 +03:00
count =
xmlOutputBufferWriteString ( writer - > out , ( const char * ) pubid ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWrite ( writer - > out , 1 , & writer - > qchar ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
}
if ( sysid ! = 0 ) {
if ( pubid = = 0 ) {
count = xmlOutputBufferWriteString ( writer - > out , " SYSTEM " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
}
count = xmlOutputBufferWriteString ( writer - > out , " " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWrite ( writer - > out , 1 , & writer - > qchar ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
2003-11-20 14:59:09 +03:00
count =
xmlOutputBufferWriteString ( writer - > out , ( const char * ) sysid ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWrite ( writer - > out , 1 , & writer - > qchar ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
}
if ( ndataid ! = NULL ) {
count = xmlOutputBufferWriteString ( writer - > out , " NDATA " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
2003-11-20 14:59:09 +03:00
count =
xmlOutputBufferWriteString ( writer - > out ,
( const char * ) ndataid ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
}
return sum ;
}
2003-11-20 14:59:09 +03:00
/**
* xmlTextWriterWriteDTDNotation :
* @ writer : the xmlTextWriterPtr
* @ name : the name of the xml notation
* @ pubid : the public identifier , which is an alternative to the system identifier
* @ sysid : the system identifier , which is the URI of the DTD
*
* Write a DTD entity .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
2003-10-21 02:32:39 +04:00
int
xmlTextWriterWriteDTDNotation ( xmlTextWriterPtr writer ,
const xmlChar * name ,
const xmlChar * pubid , const xmlChar * sysid )
{
int count ;
int sum ;
xmlLinkPtr lk ;
xmlTextWriterStackEntry * p ;
if ( writer = = NULL | | name = = NULL | | * name = = ' \0 ' )
return - 1 ;
sum = 0 ;
lk = xmlListFront ( writer - > nodes ) ;
if ( lk = = 0 ) {
return - 1 ;
}
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
2004-03-22 18:22:58 +03:00
if ( p ! = 0 ) {
switch ( p - > state ) {
case XML_TEXTWRITER_DTD :
count = xmlOutputBufferWriteString ( writer - > out , " [ " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
if ( writer - > indent ) {
count = xmlOutputBufferWriteString ( writer - > out , " \n " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
}
p - > state = XML_TEXTWRITER_DTD_TEXT ;
/* fallthrough */
case XML_TEXTWRITER_DTD_TEXT :
break ;
default :
2003-10-21 02:32:39 +04:00
return - 1 ;
2004-03-22 18:22:58 +03:00
}
}
if ( writer - > indent ) {
count = xmlTextWriterWriteIndent ( writer ) ;
if ( count < 0 )
2003-10-21 02:32:39 +04:00
return - 1 ;
2004-03-22 18:22:58 +03:00
sum + = count ;
2003-10-21 02:32:39 +04:00
}
count = xmlOutputBufferWriteString ( writer - > out , " <!NOTATION " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWriteString ( writer - > out , ( const char * ) name ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
if ( pubid ! = 0 ) {
count = xmlOutputBufferWriteString ( writer - > out , " PUBLIC " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWrite ( writer - > out , 1 , & writer - > qchar ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
2003-11-20 14:59:09 +03:00
count =
xmlOutputBufferWriteString ( writer - > out , ( const char * ) pubid ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWrite ( writer - > out , 1 , & writer - > qchar ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
}
if ( sysid ! = 0 ) {
if ( pubid = = 0 ) {
count = xmlOutputBufferWriteString ( writer - > out , " SYSTEM " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
}
count = xmlOutputBufferWriteString ( writer - > out , " " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWrite ( writer - > out , 1 , & writer - > qchar ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
2003-11-20 14:59:09 +03:00
count =
xmlOutputBufferWriteString ( writer - > out , ( const char * ) sysid ) ;
2003-10-21 02:32:39 +04:00
if ( count < 0 )
return - 1 ;
sum + = count ;
count = xmlOutputBufferWrite ( writer - > out , 1 , & writer - > qchar ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
}
count = xmlOutputBufferWriteString ( writer - > out , " > " ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
return sum ;
}
/**
* xmlTextWriterFlush :
* @ writer : the xmlTextWriterPtr
*
* Flush the output buffer .
*
* Returns the bytes written ( may be 0 because of buffering ) or - 1 in case of error
*/
int
xmlTextWriterFlush ( xmlTextWriterPtr writer )
{
int count ;
if ( writer = = NULL )
return - 1 ;
if ( writer - > out = = NULL )
count = 0 ;
else
count = xmlOutputBufferFlush ( writer - > out ) ;
return count ;
}
/**
* misc
*/
/**
* xmlFreeTextWriterStackEntry :
* @ lk : the xmlLinkPtr
*
* Free callback for the xmlList .
*/
static void
xmlFreeTextWriterStackEntry ( xmlLinkPtr lk )
{
xmlTextWriterStackEntry * p ;
p = ( xmlTextWriterStackEntry * ) xmlLinkGetData ( lk ) ;
if ( p = = 0 )
return ;
if ( p - > name ! = 0 )
xmlFree ( p - > name ) ;
xmlFree ( p ) ;
}
/**
* xmlCmpTextWriterStackEntry :
* @ data0 : the first data
* @ data1 : the second data
*
* Compare callback for the xmlList .
*
* Returns - 1 , 0 , 1
*/
static int
xmlCmpTextWriterStackEntry ( const void * data0 , const void * data1 )
{
xmlTextWriterStackEntry * p0 ;
xmlTextWriterStackEntry * p1 ;
if ( data0 = = data1 )
return 0 ;
if ( data0 = = 0 )
return - 1 ;
if ( data1 = = 0 )
return 1 ;
p0 = ( xmlTextWriterStackEntry * ) data0 ;
p1 = ( xmlTextWriterStackEntry * ) data1 ;
return xmlStrcmp ( p0 - > name , p1 - > name ) ;
}
/**
* misc
*/
2007-06-08 12:50:47 +04:00
/**
* xmlTextWriterOutputNSDecl :
* @ writer : the xmlTextWriterPtr
*
* Output the current namespace declarations .
*/
static int
xmlTextWriterOutputNSDecl ( xmlTextWriterPtr writer )
{
xmlLinkPtr lk ;
xmlTextWriterNsStackEntry * np ;
int count ;
int sum ;
sum = 0 ;
while ( ! xmlListEmpty ( writer - > nsstack ) ) {
xmlChar * namespaceURI = NULL ;
xmlChar * prefix = NULL ;
lk = xmlListFront ( writer - > nsstack ) ;
np = ( xmlTextWriterNsStackEntry * ) xmlLinkGetData ( lk ) ;
if ( np ! = 0 ) {
namespaceURI = xmlStrdup ( np - > uri ) ;
prefix = xmlStrdup ( np - > prefix ) ;
}
xmlListPopFront ( writer - > nsstack ) ;
if ( np ! = 0 ) {
count = xmlTextWriterWriteAttribute ( writer , prefix , namespaceURI ) ;
xmlFree ( namespaceURI ) ;
xmlFree ( prefix ) ;
if ( count < 0 ) {
xmlListDelete ( writer - > nsstack ) ;
writer - > nsstack = NULL ;
return - 1 ;
}
sum + = count ;
}
}
return sum ;
}
2003-10-21 02:32:39 +04:00
/**
* xmlFreeTextWriterNsStackEntry :
* @ lk : the xmlLinkPtr
*
* Free callback for the xmlList .
*/
static void
xmlFreeTextWriterNsStackEntry ( xmlLinkPtr lk )
{
xmlTextWriterNsStackEntry * p ;
p = ( xmlTextWriterNsStackEntry * ) xmlLinkGetData ( lk ) ;
if ( p = = 0 )
return ;
if ( p - > prefix ! = 0 )
xmlFree ( p - > prefix ) ;
if ( p - > uri ! = 0 )
xmlFree ( p - > uri ) ;
xmlFree ( p ) ;
}
/**
* xmlCmpTextWriterNsStackEntry :
* @ data0 : the first data
* @ data1 : the second data
*
* Compare callback for the xmlList .
*
* Returns - 1 , 0 , 1
*/
static int
xmlCmpTextWriterNsStackEntry ( const void * data0 , const void * data1 )
{
xmlTextWriterNsStackEntry * p0 ;
xmlTextWriterNsStackEntry * p1 ;
int rc ;
if ( data0 = = data1 )
return 0 ;
if ( data0 = = 0 )
return - 1 ;
if ( data1 = = 0 )
return 1 ;
p0 = ( xmlTextWriterNsStackEntry * ) data0 ;
p1 = ( xmlTextWriterNsStackEntry * ) data1 ;
rc = xmlStrcmp ( p0 - > prefix , p1 - > prefix ) ;
2007-06-08 12:50:47 +04:00
if ( ( rc ! = 0 ) | | ( p0 - > elem ! = p1 - > elem ) )
rc = - 1 ;
2003-10-21 02:32:39 +04:00
return rc ;
}
2003-11-20 14:59:09 +03:00
/**
* xmlTextWriterWriteDocCallback :
* @ context : the xmlBufferPtr
* @ str : the data to write
* @ len : the length of the data
*
* Write callback for the xmlOutputBuffer with target xmlBuffer
*
* Returns - 1 , 0 , 1
*/
static int
2017-11-09 19:47:47 +03:00
xmlTextWriterWriteDocCallback ( void * context , const char * str , int len )
2003-11-20 14:59:09 +03:00
{
xmlParserCtxtPtr ctxt = ( xmlParserCtxtPtr ) context ;
int rc ;
2017-11-09 19:47:47 +03:00
if ( ( rc = xmlParseChunk ( ctxt , str , len , 0 ) ) ! = 0 ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsgInt ( NULL , XML_ERR_INTERNAL_ERROR ,
2003-11-20 14:59:09 +03:00
" xmlTextWriterWriteDocCallback : XML error %d ! \n " ,
rc ) ;
return - 1 ;
}
return len ;
}
/**
* xmlTextWriterCloseDocCallback :
* @ context : the xmlBufferPtr
*
* Close callback for the xmlOutputBuffer with target xmlBuffer
*
* Returns - 1 , 0 , 1
*/
static int
xmlTextWriterCloseDocCallback ( void * context )
{
xmlParserCtxtPtr ctxt = ( xmlParserCtxtPtr ) context ;
int rc ;
if ( ( rc = xmlParseChunk ( ctxt , NULL , 0 , 1 ) ) ! = 0 ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsgInt ( NULL , XML_ERR_INTERNAL_ERROR ,
2017-11-09 19:47:47 +03:00
" xmlTextWriterCloseDocCallback : XML error %d ! \n " ,
2003-11-20 14:59:09 +03:00
rc ) ;
return - 1 ;
}
return 0 ;
}
2003-10-21 02:32:39 +04:00
/**
* xmlTextWriterVSprintf :
* @ format : see printf
* @ argptr : pointer to the first member of the variable argument list .
*
* Utility function for formatted output
*
* Returns a new xmlChar buffer with the data or NULL on error . This buffer must be freed .
*/
static xmlChar *
xmlTextWriterVSprintf ( const char * format , va_list argptr )
{
int size ;
int count ;
xmlChar * buf ;
2005-10-20 13:04:05 +04:00
va_list locarg ;
2003-10-21 02:32:39 +04:00
size = BUFSIZ ;
buf = ( xmlChar * ) xmlMalloc ( size ) ;
if ( buf = = NULL ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( NULL , XML_ERR_NO_MEMORY ,
2003-10-21 02:32:39 +04:00
" xmlTextWriterVSprintf : out of memory! \n " ) ;
return NULL ;
}
2005-10-20 13:04:05 +04:00
VA_COPY ( locarg , argptr ) ;
while ( ( ( count = vsnprintf ( ( char * ) buf , size , format , locarg ) ) < 0 )
2003-10-21 02:32:39 +04:00
| | ( count = = size - 1 ) | | ( count = = size ) | | ( count > size ) ) {
2005-10-20 13:04:05 +04:00
va_end ( locarg ) ;
2003-10-21 02:32:39 +04:00
xmlFree ( buf ) ;
size + = BUFSIZ ;
buf = ( xmlChar * ) xmlMalloc ( size ) ;
if ( buf = = NULL ) {
2004-11-03 17:20:29 +03:00
xmlWriterErrMsg ( NULL , XML_ERR_NO_MEMORY ,
2003-10-21 02:32:39 +04:00
" xmlTextWriterVSprintf : out of memory! \n " ) ;
return NULL ;
}
2005-10-20 13:04:05 +04:00
VA_COPY ( locarg , argptr ) ;
2003-10-21 02:32:39 +04:00
}
2005-10-20 13:04:05 +04:00
va_end ( locarg ) ;
2003-10-21 02:32:39 +04:00
return buf ;
}
2003-11-20 14:59:09 +03:00
/**
* xmlTextWriterStartDocumentCallback :
* @ ctx : the user data ( XML parser context )
*
* called at the start of document processing .
*/
static void
xmlTextWriterStartDocumentCallback ( void * ctx )
{
xmlParserCtxtPtr ctxt = ( xmlParserCtxtPtr ) ctx ;
xmlDocPtr doc ;
if ( ctxt - > html ) {
# ifdef LIBXML_HTML_ENABLED
if ( ctxt - > myDoc = = NULL )
ctxt - > myDoc = htmlNewDocNoDtD ( NULL , NULL ) ;
if ( ctxt - > myDoc = = NULL ) {
if ( ( ctxt - > sax ! = NULL ) & & ( ctxt - > sax - > error ! = NULL ) )
ctxt - > sax - > error ( ctxt - > userData ,
" SAX.startDocument(): out of memory \n " ) ;
ctxt - > errNo = XML_ERR_NO_MEMORY ;
ctxt - > instate = XML_PARSER_EOF ;
ctxt - > disableSAX = 1 ;
return ;
}
# else
2004-11-09 19:17:02 +03:00
xmlWriterErrMsg ( NULL , XML_ERR_INTERNAL_ERROR ,
2003-11-20 14:59:09 +03:00
" libxml2 built without HTML support \n " ) ;
ctxt - > errNo = XML_ERR_INTERNAL_ERROR ;
ctxt - > instate = XML_PARSER_EOF ;
ctxt - > disableSAX = 1 ;
return ;
# endif
} else {
doc = ctxt - > myDoc ;
if ( doc = = NULL )
doc = ctxt - > myDoc = xmlNewDoc ( ctxt - > version ) ;
if ( doc ! = NULL ) {
if ( doc - > children = = NULL ) {
if ( ctxt - > encoding ! = NULL )
doc - > encoding = xmlStrdup ( ctxt - > encoding ) ;
else
doc - > encoding = NULL ;
doc - > standalone = ctxt - > standalone ;
}
} else {
if ( ( ctxt - > sax ! = NULL ) & & ( ctxt - > sax - > error ! = NULL ) )
ctxt - > sax - > error ( ctxt - > userData ,
" SAX.startDocument(): out of memory \n " ) ;
ctxt - > errNo = XML_ERR_NO_MEMORY ;
ctxt - > instate = XML_PARSER_EOF ;
ctxt - > disableSAX = 1 ;
return ;
}
}
if ( ( ctxt - > myDoc ! = NULL ) & & ( ctxt - > myDoc - > URL = = NULL ) & &
( ctxt - > input ! = NULL ) & & ( ctxt - > input - > filename ! = NULL ) ) {
ctxt - > myDoc - > URL =
xmlCanonicPath ( ( const xmlChar * ) ctxt - > input - > filename ) ;
if ( ctxt - > myDoc - > URL = = NULL )
ctxt - > myDoc - > URL =
xmlStrdup ( ( const xmlChar * ) ctxt - > input - > filename ) ;
}
}
2004-01-02 23:04:23 +03:00
/**
* xmlTextWriterSetIndent :
* @ writer : the xmlTextWriterPtr
* @ indent : do indentation ?
*
* Set indentation output . indent = 0 do not indentation . indent > 0 do indentation .
*
* Returns - 1 on error or 0 otherwise .
*/
int
2004-02-17 14:40:32 +03:00
xmlTextWriterSetIndent ( xmlTextWriterPtr writer , int indent )
2004-01-02 23:04:23 +03:00
{
2004-11-03 14:50:29 +03:00
if ( ( writer = = NULL ) | | ( indent < 0 ) )
2004-02-17 14:40:32 +03:00
return - 1 ;
2004-01-02 23:04:23 +03:00
2004-02-17 14:40:32 +03:00
writer - > indent = indent ;
writer - > doindent = 1 ;
2004-01-02 23:04:23 +03:00
2004-02-17 14:40:32 +03:00
return 0 ;
2004-01-02 23:04:23 +03:00
}
/**
* xmlTextWriterSetIndentString :
* @ writer : the xmlTextWriterPtr
* @ str : the xmlChar string
*
* Set string indentation .
*
* Returns - 1 on error or 0 otherwise .
*/
int
2004-02-17 14:40:32 +03:00
xmlTextWriterSetIndentString ( xmlTextWriterPtr writer , const xmlChar * str )
2004-01-02 23:04:23 +03:00
{
2004-11-03 14:50:29 +03:00
if ( ( writer = = NULL ) | | ( ! str ) )
2004-02-17 14:40:32 +03:00
return - 1 ;
2004-01-02 23:04:23 +03:00
2004-02-17 14:40:32 +03:00
if ( writer - > ichar ! = NULL )
xmlFree ( writer - > ichar ) ;
writer - > ichar = xmlStrdup ( str ) ;
if ( ! writer - > ichar )
return - 1 ;
else
return 0 ;
2004-01-02 23:04:23 +03:00
}
2012-09-11 07:50:25 +04:00
/**
* xmlTextWriterSetQuoteChar :
* @ writer : the xmlTextWriterPtr
* @ quotechar : the quote character
*
* Set the character used for quoting attributes .
*
* Returns - 1 on error or 0 otherwise .
*/
int
xmlTextWriterSetQuoteChar ( xmlTextWriterPtr writer , xmlChar quotechar )
{
if ( ( writer = = NULL ) | | ( ( quotechar ! = ' \' ' ) & & ( quotechar ! = ' " ' ) ) )
return - 1 ;
writer - > qchar = quotechar ;
return 0 ;
}
2004-01-02 23:04:23 +03:00
/**
* xmlTextWriterWriteIndent :
* @ writer : the xmlTextWriterPtr
*
* Write indent string .
*
* Returns - 1 on error or the number of strings written .
2004-02-17 14:40:32 +03:00
*/
2004-01-02 23:04:23 +03:00
static int
2004-02-17 14:40:32 +03:00
xmlTextWriterWriteIndent ( xmlTextWriterPtr writer )
{
int lksize ;
int i ;
int ret ;
lksize = xmlListSize ( writer - > nodes ) ;
if ( lksize < 1 )
return ( - 1 ) ; /* list is empty */
for ( i = 0 ; i < ( lksize - 1 ) ; i + + ) {
ret = xmlOutputBufferWriteString ( writer - > out ,
( const char * ) writer - > ichar ) ;
if ( ret = = - 1 )
return ( - 1 ) ;
}
return ( lksize - 1 ) ;
2004-01-02 23:04:23 +03:00
}
2004-03-22 18:22:58 +03:00
/**
* xmlTextWriterHandleStateDependencies :
* @ writer : the xmlTextWriterPtr
* @ p : the xmlTextWriterStackEntry
*
* Write state dependent strings .
*
* Returns - 1 on error or the number of characters written .
*/
static int
xmlTextWriterHandleStateDependencies ( xmlTextWriterPtr writer ,
xmlTextWriterStackEntry * p )
{
int count ;
int sum ;
char extra [ 3 ] ;
if ( writer = = NULL )
return - 1 ;
if ( p = = NULL )
return 0 ;
sum = 0 ;
extra [ 0 ] = extra [ 1 ] = extra [ 2 ] = ' \0 ' ;
if ( p ! = 0 ) {
sum = 0 ;
switch ( p - > state ) {
case XML_TEXTWRITER_NAME :
2007-06-08 12:50:47 +04:00
/* Output namespace declarations */
count = xmlTextWriterOutputNSDecl ( writer ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
2004-03-22 18:22:58 +03:00
extra [ 0 ] = ' > ' ;
p - > state = XML_TEXTWRITER_TEXT ;
break ;
case XML_TEXTWRITER_PI :
extra [ 0 ] = ' ' ;
p - > state = XML_TEXTWRITER_PI_TEXT ;
break ;
case XML_TEXTWRITER_DTD :
extra [ 0 ] = ' ' ;
extra [ 1 ] = ' [ ' ;
p - > state = XML_TEXTWRITER_DTD_TEXT ;
break ;
case XML_TEXTWRITER_DTD_ELEM :
extra [ 0 ] = ' ' ;
p - > state = XML_TEXTWRITER_DTD_ELEM_TEXT ;
break ;
case XML_TEXTWRITER_DTD_ATTL :
extra [ 0 ] = ' ' ;
p - > state = XML_TEXTWRITER_DTD_ATTL_TEXT ;
break ;
case XML_TEXTWRITER_DTD_ENTY :
case XML_TEXTWRITER_DTD_PENT :
extra [ 0 ] = ' ' ;
extra [ 1 ] = writer - > qchar ;
p - > state = XML_TEXTWRITER_DTD_ENTY_TEXT ;
break ;
default :
break ;
}
}
if ( * extra ! = ' \0 ' ) {
count = xmlOutputBufferWriteString ( writer - > out , extra ) ;
if ( count < 0 )
return - 1 ;
sum + = count ;
}
return sum ;
}
2005-04-01 17:11:58 +04:00
# define bottom_xmlwriter
# include "elfgcchack.h"
2003-10-21 02:32:39 +04:00
# endif