From 500a1de533e2ea03f452844f537bb247b7e43af2 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Mon, 22 Mar 2004 15:22:58 +0000 Subject: [PATCH] applied patch from Alfred Mickautsch for better DTD support. fixed bug * xmlwriter.c include/libxml/xmlwriter.h doc/* : applied patch from Alfred Mickautsch for better DTD support. * SAX2.c HTMLparser.c parser.c xinclude.c xmllint.c xmlreader.c xmlschemas.c: fixed bug #137867 i.e. fixed properly the way reference counting is handled in the XML parser which had the side effect of removing a lot of hazardous cruft added to try to fix the problems associated as they popped up. * xmlIO.c: FILE * close fixup for stderr/stdout Daniel --- ChangeLog | 11 + HTMLparser.c | 6 - SAX2.c | 4 +- doc/APIchunk10.html | 31 +- doc/APIchunk14.html | 1 + doc/APIchunk15.html | 1 - doc/APIchunk17.html | 8 +- doc/APIchunk18.html | 2 + doc/APIchunk2.html | 3 + doc/APIchunk20.html | 3 +- doc/APIchunk22.html | 1 + doc/APIchunk25.html | 6 +- doc/APIchunk26.html | 1 + doc/APIchunk4.html | 2 +- doc/APIchunk8.html | 3 + doc/APIfiles.html | 1 + doc/APIfunctions.html | 5 + doc/APIsymbols.html | 1 + doc/html/libxml-tree.html | 18 +- doc/html/libxml-xmlwriter.html | 21 +- doc/libxml2-api.xml | 61 +- doc/libxml2-refs.xml | 76 ++- include/libxml/xmlwriter.h | 206 +++---- parser.c | 15 +- python/libxml2class.txt | 476 ++++++++-------- win32/libxml2.def.src | 12 + xinclude.c | 10 +- xmlIO.c | 10 +- xmllint.c | 1 + xmlreader.c | 6 +- xmlschemas.c | 2 +- xmlwriter.c | 989 +++++++++++++++++++++------------ 32 files changed, 1148 insertions(+), 845 deletions(-) diff --git a/ChangeLog b/ChangeLog index 71ba7041..25d25c02 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Mon Mar 22 16:16:18 CET 2004 Daniel Veillard + + * xmlwriter.c include/libxml/xmlwriter.h doc/* : applied patch from + Alfred Mickautsch for better DTD support. + * SAX2.c HTMLparser.c parser.c xinclude.c xmllint.c xmlreader.c + xmlschemas.c: fixed bug #137867 i.e. fixed properly the way + reference counting is handled in the XML parser which had the + side effect of removing a lot of hazardous cruft added to try + to fix the problems associated as they popped up. + * xmlIO.c: FILE * close fixup for stderr/stdout + Sun Mar 21 19:19:41 HKT 2004 William Brack * relaxng.c: added an error message when an element is not diff --git a/HTMLparser.c b/HTMLparser.c index c428ead2..6cbe67e6 100644 --- a/HTMLparser.c +++ b/HTMLparser.c @@ -5574,12 +5574,6 @@ htmlDoRead(htmlParserCtxtPtr ctxt, const char *URL, const char *encoding, (ret->dict == ctxt->dict)) ctxt->dict = NULL; xmlFreeParserCtxt(ctxt); - } else { - /* Must duplicate the reference to the dictionary */ - if ((ctxt->dictNames) && - (ret != NULL) && - (ret->dict == ctxt->dict)) - xmlDictReference(ctxt->dict); } return (ret); } diff --git a/SAX2.c b/SAX2.c index d27d5748..e6e310e0 100644 --- a/SAX2.c +++ b/SAX2.c @@ -839,8 +839,10 @@ xmlSAX2StartDocument(void *ctx) ctxt->disableSAX = 1; return; } - if ((ctxt->dictNames) && (doc != NULL)) + if ((ctxt->dictNames) && (doc != NULL)) { doc->dict = ctxt->dict; + xmlDictReference(doc->dict); + } } if ((ctxt->myDoc != NULL) && (ctxt->myDoc->URL == NULL) && (ctxt->input != NULL) && (ctxt->input->filename != NULL)) { diff --git a/doc/APIchunk10.html b/doc/APIchunk10.html index 6def6a85..baeacb65 100644 --- a/doc/APIchunk10.html +++ b/doc/APIchunk10.html @@ -47,6 +47,7 @@ A:link, A:visited, A:active { text-decoration: underline } xmlParseReference
xmlSAXUserParseFile
xmlSAXUserParseMemory
+xmlSaveFormatFileTo
xmlSetEntityReferenceFunc
xmlTextReaderCurrentDoc
xmlTextReaderExpand
@@ -265,34 +266,6 @@ A:link, A:visited, A:active { text-decoration: underline } _xmlDoc
_xmlDtd
_xmlNode
-
children
htmlAutoCloseTag
-htmlNodeDump
-htmlNodeDumpFile
-htmlNodeDumpFileFormat
-htmlNodeDumpFormatOutput
-htmlNodeDumpOutput
-xmlAddChild
-xmlAddNextSibling
-xmlAddPrevSibling
-xmlChildrenNode
-xmlDocGetRootElement
-xmlDocSetRootElement
-xmlElemDump
-xmlFreeNode
-xmlFreeNodeList
-xmlFreePropList
-xmlLsCountNode
-xmlNewChild
-xmlNewTextChild
-xmlNewTextWriterTree
-xmlNodeDump
-xmlNodeDumpOutput
-xmlParseElementChildrenContentDecl
-xmlParseElementContentDecl
-xmlRootNode
-xmlValidGetPotentialChildren
-xmlValidGetValidElements
-xmlXPathNextChild
childrens
_xmlEntity
childs
_xmlNode
xmlIsMixedElement
@@ -340,6 +313,7 @@ A:link, A:visited, A:active { text-decoration: underline } xmlReadFd
xmlReaderForFd
xmlReaderNewFd
+xmlSaveFormatFileTo
xmlTextWriterEndDocument
closes
xmlNanoHTTPClose
xmlNanoHTTPSave
@@ -669,6 +643,7 @@ A:link, A:visited, A:active { text-decoration: underline } xmlTextReaderReadInnerXml
xmlTextReaderReadOuterXml
xmlTextReaderReadString
+xmlTextWriterWriteDTDExternalEntityContents
contentspec
xmlParseElementContentDecl
xmlParseElementDecl
contextual
xmlRelaxNGGetParserErrors
diff --git a/doc/APIchunk14.html b/doc/APIchunk14.html index b85c1ef2..8f434296 100644 --- a/doc/APIchunk14.html +++ b/doc/APIchunk14.html @@ -237,6 +237,7 @@ A:link, A:visited, A:active { text-decoration: underline } xmlStrEqual
xmlTextReaderHasValue
xmlTextReaderReadAttributeValue
+xmlTextWriterWriteDTDExternalEntity
xmlValidateDocumentFinal
xmlValidateDtdFinal
xmlXPathIdFunction
diff --git a/doc/APIchunk15.html b/doc/APIchunk15.html index a177b2b1..b82ce9af 100644 --- a/doc/APIchunk15.html +++ b/doc/APIchunk15.html @@ -175,7 +175,6 @@ A:link, A:visited, A:active { text-decoration: underline } xmlNodeDumpOutput
xmlSaveFormatFile
xmlSaveFormatFileEnc
-xmlSaveFormatFileTo
independently
xmlGetProp
xmlParseAttribute
index
index
diff --git a/doc/APIchunk17.html b/doc/APIchunk17.html index df28dfca..bea20d1f 100644 --- a/doc/APIchunk17.html +++ b/doc/APIchunk17.html @@ -35,10 +35,7 @@ A:link, A:visited, A:active { text-decoration: underline } x-x y-z

Letter m:

machine
xmlCheckFilename
-
macro
xmlTextWriterEndDTDAttlist
-xmlTextWriterEndDTDElement
-xmlTextWriterEndDTDEntity
-xmlTextWriterWriteDocType
+
macro
xmlTextWriterWriteDocType
xmlTextWriterWriteProcessingInstruction
made
LIBXML_ISO8859X_ENABLED
xmlCharEncOutFunc
@@ -76,9 +73,6 @@ A:link, A:visited, A:active { text-decoration: underline }
many
_xmlParserInput
xmlXPathStringFunction
maps
xmlTextReaderLookupNamespace
-xmlTextWriterEndDTDAttlist
-xmlTextWriterEndDTDElement
-xmlTextWriterEndDTDEntity
xmlTextWriterWriteDocType
xmlTextWriterWriteProcessingInstruction
mark
xmlStrcat
diff --git a/doc/APIchunk18.html b/doc/APIchunk18.html index 5252a66f..62d47a26 100644 --- a/doc/APIchunk18.html +++ b/doc/APIchunk18.html @@ -57,6 +57,8 @@ A:link, A:visited, A:active { text-decoration: underline } xmlC14NDocSaveTo
xmlC14NExecute
xmlCopyDoc
+xmlCopyNode
+xmlDocCopyNode
xmlFreeNsList
xmlGetProp
xmlReconciliateNs
diff --git a/doc/APIchunk2.html b/doc/APIchunk2.html index 43ab5825..52e3b648 100644 --- a/doc/APIchunk2.html +++ b/doc/APIchunk2.html @@ -284,6 +284,9 @@ A:link, A:visited, A:active { text-decoration: underline } xmlTextWriterEndCDATA
xmlTextWriterEndComment
xmlTextWriterEndDTD
+xmlTextWriterEndDTDAttlist
+xmlTextWriterEndDTDElement
+xmlTextWriterEndDTDEntity
xmlTextWriterEndDocument
xmlTextWriterEndElement
xmlTextWriterEndPI
diff --git a/doc/APIchunk20.html b/doc/APIchunk20.html index 10ad6e02..b335510b 100644 --- a/doc/APIchunk20.html +++ b/doc/APIchunk20.html @@ -409,6 +409,8 @@ A:link, A:visited, A:active { text-decoration: underline } xmlAddChild
xmlAddNextSibling
xmlAddPrevSibling
+xmlCopyNode
+xmlDocCopyNode
xmlTextReaderRead
xmlTextReaderSetParserProp
property
_xmlAttr
@@ -441,7 +443,6 @@ A:link, A:visited, A:active { text-decoration: underline } xmlOutputMatchCallback
xmlSaveFormatFile
xmlSaveFormatFileEnc
-xmlSaveFormatFileTo
xmlSchemaValidateStream
xmlUTF8Strloc
xmlUTF8Strpos
diff --git a/doc/APIchunk22.html b/doc/APIchunk22.html index 15e00971..bac06733 100644 --- a/doc/APIchunk22.html +++ b/doc/APIchunk22.html @@ -500,6 +500,7 @@ A:link, A:visited, A:active { text-decoration: underline } xmlXPtrNewRange
start-tag
xmlParseElement
xmlParseStartTag
+
started
xmlTextWriterWriteDTDExternalEntity
starting
xmlAutomataNewAllTrans
xmlAutomataNewCountTrans
xmlAutomataNewCountedTrans
diff --git a/doc/APIchunk25.html b/doc/APIchunk25.html index cabe9f1d..8dc92c9a 100644 --- a/doc/APIchunk25.html +++ b/doc/APIchunk25.html @@ -191,7 +191,6 @@ A:link, A:visited, A:active { text-decoration: underline } xmlNodeDumpOutput
xmlSaveFormatFile
xmlSaveFormatFileEnc
-xmlSaveFormatFileTo
xmlInitParser
htmlInitAutoClose
xmlInitThreads
xmlInitThreads
xmlInitializeCatalog
xmlCatalogAdd
@@ -223,7 +222,6 @@ A:link, A:visited, A:active { text-decoration: underline } xmlNodeDumpOutput
xmlSaveFormatFile
xmlSaveFormatFileEnc
-xmlSaveFormatFileTo
xmlLineNumbersDefault
xmlGetLineNo
xmlListWalk
xmlListWalker
xmlLoadExtDtdDefaultValue
XML_COMPLETE_ATTRS
@@ -384,9 +382,7 @@ A:link, A:visited, A:active { text-decoration: underline }
xmlTextReaderLocatorPtr
xmlTextReaderLocatorBaseURI
xmlTextReaderLocatorLineNumber
xmlTextReaderRead
xmlTextReaderExpand
-
xmlTextWriterEndDTD
xmlTextWriterEndDTDAttlist
-xmlTextWriterEndDTDElement
-xmlTextWriterEndDTDEntity
+
xmlTextWriterStartDTDEntity
xmlTextWriterWriteDTDExternalEntity
xmlTextWriterWriteDTD
xmlTextWriterWriteDocType
xmlTextWriterWritePI
xmlTextWriterWriteProcessingInstruction
xmlURI
xmlCreateURI
diff --git a/doc/APIchunk26.html b/doc/APIchunk26.html index 6bfdb9dc..6c22f43d 100644 --- a/doc/APIchunk26.html +++ b/doc/APIchunk26.html @@ -60,6 +60,7 @@ A:link, A:visited, A:active { text-decoration: underline } xmlBufferCCat
xmlBufferCat
xmlByteConsumed
+xmlCopyDoc
xmlCtxtReadDoc
xmlDocDumpMemory
xmlOutputBufferWriteString
diff --git a/doc/APIchunk4.html b/doc/APIchunk4.html index 88638569..eded8bbf 100644 --- a/doc/APIchunk4.html +++ b/doc/APIchunk4.html @@ -197,6 +197,7 @@ A:link, A:visited, A:active { text-decoration: underline } xmlParseExternalID
xmlParsePEReference
xmlParserHandlePEReference
+xmlSaveFormatFileTo
xmlTextReaderCurrentDoc
NRK
_htmlElemDesc
NSDef
xmlNamespaceParseNSDef
@@ -287,7 +288,6 @@ A:link, A:visited, A:active { text-decoration: underline } xmlSAXDefaultVersion
xmlSaveFormatFile
xmlSaveFormatFileEnc
-xmlSaveFormatFileTo
xmlTextReaderSetParserProp
Note:
fatalErrorSAXFunc
xmlCharEncodingOutputFunc
diff --git a/doc/APIchunk8.html b/doc/APIchunk8.html index 50673e4b..210b4665 100644 --- a/doc/APIchunk8.html +++ b/doc/APIchunk8.html @@ -493,6 +493,7 @@ A:link, A:visited, A:active { text-decoration: underline } xmlTextWriterWriteDTD
xmlTextWriterWriteDTDEntity
xmlTextWriterWriteDTDExternalEntity
+xmlTextWriterWriteDTDExternalEntityContents
xmlTextWriterWriteDTDNotation
xmlTextWriterWriteFormatDTD
xmlTextWriterWriteVFormatDTD
@@ -561,6 +562,8 @@ A:link, A:visited, A:active { text-decoration: underline }
appended
xmlParseAttValue
appending
xmlParseAttValue
appendix
xmlDetectCharEncoding
+
applicable
xmlCopyNode
+xmlDocCopyNode
application
_xmlAttr
_xmlAttribute
_xmlDoc
diff --git a/doc/APIfiles.html b/doc/APIfiles.html index a36f187a..de3c2705 100644 --- a/doc/APIfiles.html +++ b/doc/APIfiles.html @@ -2550,6 +2550,7 @@ A:link, A:visited, A:active { text-decoration: underline } xmlTextWriterWriteDTDElement
xmlTextWriterWriteDTDEntity
xmlTextWriterWriteDTDExternalEntity
+xmlTextWriterWriteDTDExternalEntityContents
xmlTextWriterWriteDTDInternalEntity
xmlTextWriterWriteDTDNotation
xmlTextWriterWriteDocType
diff --git a/doc/APIfunctions.html b/doc/APIfunctions.html index f18e9882..290aea42 100644 --- a/doc/APIfunctions.html +++ b/doc/APIfunctions.html @@ -387,6 +387,7 @@ A:link, A:visited, A:active { text-decoration: underline } xmlTextWriterWriteDTDElement
xmlTextWriterWriteDTDEntity
xmlTextWriterWriteDTDExternalEntity
+xmlTextWriterWriteDTDExternalEntityContents
xmlTextWriterWriteDTDInternalEntity
xmlTextWriterWriteDTDNotation
xmlTextWriterWriteElement
@@ -1845,6 +1846,9 @@ A:link, A:visited, A:active { text-decoration: underline } xmlTextWriterEndCDATA
xmlTextWriterEndComment
xmlTextWriterEndDTD
+xmlTextWriterEndDTDAttlist
+xmlTextWriterEndDTDElement
+xmlTextWriterEndDTDEntity
xmlTextWriterEndDocument
xmlTextWriterEndElement
xmlTextWriterEndPI
@@ -1875,6 +1879,7 @@ A:link, A:visited, A:active { text-decoration: underline } xmlTextWriterWriteDTDElement
xmlTextWriterWriteDTDEntity
xmlTextWriterWriteDTDExternalEntity
+xmlTextWriterWriteDTDExternalEntityContents
xmlTextWriterWriteDTDInternalEntity
xmlTextWriterWriteDTDNotation
xmlTextWriterWriteElement
diff --git a/doc/APIsymbols.html b/doc/APIsymbols.html index 973b478e..b3d570f9 100644 --- a/doc/APIsymbols.html +++ b/doc/APIsymbols.html @@ -2356,6 +2356,7 @@ A:link, A:visited, A:active { text-decoration: underline } xmlTextWriterWriteDTDElement
xmlTextWriterWriteDTDEntity
xmlTextWriterWriteDTDExternalEntity
+xmlTextWriterWriteDTDExternalEntityContents
xmlTextWriterWriteDTDInternalEntity
xmlTextWriterWriteDTDNotation
xmlTextWriterWriteDocType
diff --git a/doc/html/libxml-tree.html b/doc/html/libxml-tree.html index 4a2d6a56..b9529198 100644 --- a/doc/html/libxml-tree.html +++ b/doc/html/libxml-tree.html @@ -88,12 +88,12 @@ A:link, A:visited, A:active { text-decoration: underline }
xmlDtdPtr	xmlCopyDtd		(xmlDtdPtr dtd)
xmlNsPtr	xmlCopyNamespace	(xmlNsPtr cur)
xmlNsPtr	xmlCopyNamespaceList	(xmlNsPtr cur)
-
xmlNodePtr	xmlCopyNode		(const xmlNodePtr node, 
int recursive)
+
xmlNodePtr	xmlCopyNode		(const xmlNodePtr node, 
int extended)
xmlNodePtr	xmlCopyNodeList		(const xmlNodePtr node)
xmlAttrPtr	xmlCopyProp		(xmlNodePtr target, 
xmlAttrPtr cur)
xmlAttrPtr	xmlCopyPropList		(xmlNodePtr target, 
xmlAttrPtr cur)
xmlDtdPtr	xmlCreateIntSubset	(xmlDocPtr doc, 
const xmlChar * name,
const xmlChar * ExternalID,
const xmlChar * SystemID)
-
xmlNodePtr	xmlDocCopyNode		(const xmlNodePtr node, 
xmlDocPtr doc,
int recursive)
+
xmlNodePtr	xmlDocCopyNode		(const xmlNodePtr node, 
xmlDocPtr doc,
int extended)
int	xmlDocDump			(FILE * f, 
xmlDocPtr cur)
void	xmlDocDumpFormatMemory		(xmlDocPtr cur, 
xmlChar ** mem,
int * size,
int format)
void	xmlDocDumpFormatMemoryEnc	(xmlDocPtr out_doc, 
xmlChar ** doc_txt_ptr,
int * doc_txt_len,
const char * txt_encoding,
int format)
@@ -644,15 +644,15 @@ A:link, A:visited, A:active { text-decoration: underline }

Builds the QName @prefix:@ncname in @memory if there is enough space and prefix is not NULL nor empty, otherwise allocate a new string. If prefix is NULL or empty it returns ncname.

ncname:the Name
prefix:the prefix
memory:preallocated memory
len:preallocated memory length
Returns:the new string which must be freed by the caller if different from @memory and @ncname or NULL in case of error

Function: xmlCopyDoc

xmlDocPtr	xmlCopyDoc		(xmlDocPtr doc, 
int recursive)

Do a copy of the document info. If recursive, the content tree will be copied too as well as DTD, namespaces and entities.

-
doc:the document
recursive:if 1 do a recursive copy.
Returns:a new #xmlDocPtr, or NULL in case of error.

Function: xmlCopyDtd

xmlDtdPtr	xmlCopyDtd		(xmlDtdPtr dtd)
+
doc:the document
recursive:if not zero do a recursive copy.
Returns:a new #xmlDocPtr, or NULL in case of error.

Function: xmlCopyDtd

xmlDtdPtr	xmlCopyDtd		(xmlDtdPtr dtd)

Do a copy of the dtd.

dtd:the dtd
Returns:a new #xmlDtdPtr, or NULL in case of error.

Function: xmlCopyNamespace

xmlNsPtr	xmlCopyNamespace	(xmlNsPtr cur)

Do a copy of the namespace.

cur:the namespace
Returns:a new #xmlNsPtr, or NULL in case of error.

Function: xmlCopyNamespaceList

xmlNsPtr	xmlCopyNamespaceList	(xmlNsPtr cur)

Do a copy of an namespace list.

-
cur:the first namespace
Returns:a new #xmlNsPtr, or NULL in case of error.

Function: xmlCopyNode

xmlNodePtr	xmlCopyNode		(const xmlNodePtr node, 
int recursive)
+
cur:the first namespace
Returns:a new #xmlNsPtr, or NULL in case of error.

Function: xmlCopyNode

xmlNodePtr	xmlCopyNode		(const xmlNodePtr node, 
int extended)

Do a copy of the node.

-
node:the node
recursive:if 1 do a recursive copy.
Returns:a new #xmlNodePtr, or NULL in case of error.

Function: xmlCopyNodeList

xmlNodePtr	xmlCopyNodeList		(const xmlNodePtr node)
+
node:the node
extended:if 1 do a recursive copy (properties, namespaces and children when applicable) if 2 copy properties and namespaces (when applicable)
Returns:a new #xmlNodePtr, or NULL in case of error.

Function: xmlCopyNodeList

xmlNodePtr	xmlCopyNodeList		(const xmlNodePtr node)

Do a recursive copy of the node list.

node:the first node in the list.
Returns:a new #xmlNodePtr, or NULL in case of error.

Function: xmlCopyProp

xmlAttrPtr	xmlCopyProp		(xmlNodePtr target, 
xmlAttrPtr cur)

Do a copy of the attribute.

@@ -660,9 +660,9 @@ A:link, A:visited, A:active { text-decoration: underline }

Do a copy of an attribute list.

target:the element where the attributes will be grafted
cur:the first attribute
Returns:a new #xmlAttrPtr, or NULL in case of error.

Function: xmlCreateIntSubset

xmlDtdPtr	xmlCreateIntSubset	(xmlDocPtr doc, 
const xmlChar * name,
const xmlChar * ExternalID,
const xmlChar * SystemID)

Create the internal subset of a document

-
doc:the document pointer
name:the DTD name
ExternalID:the external (PUBLIC) ID
SystemID:the system ID
Returns:a pointer to the new DTD structure

Function: xmlDocCopyNode

xmlNodePtr	xmlDocCopyNode		(const xmlNodePtr node, 
xmlDocPtr doc,
int recursive)
+
doc:the document pointer
name:the DTD name
ExternalID:the external (PUBLIC) ID
SystemID:the system ID
Returns:a pointer to the new DTD structure

Function: xmlDocCopyNode

xmlNodePtr	xmlDocCopyNode		(const xmlNodePtr node, 
xmlDocPtr doc,
int extended)

Do a copy of the node to a given document.

-
node:the node
doc:the document
recursive:if 1 do a recursive copy.
Returns:a new #xmlNodePtr, or NULL in case of error.

Function: xmlDocDump

int	xmlDocDump			(FILE * f, 
xmlDocPtr cur)
+
node:the node
doc:the document
extended:if 1 do a recursive copy (properties, namespaces and children when applicable) if 2 copy properties and namespaces (when applicable)
Returns:a new #xmlNodePtr, or NULL in case of error.

Function: xmlDocDump

int	xmlDocDump			(FILE * f, 
xmlDocPtr cur)

Dump an XML document to an open FILE.

f:the FILE*
cur:the document
Returns:the number of bytes written or -1 in case of failure.

Function: xmlDocDumpFormatMemory

void	xmlDocDumpFormatMemory		(xmlDocPtr cur, 
xmlChar ** mem,
int * size,
int format)

Dump an XML document in memory and return the #xmlChar * and it's size. It's up to the caller to free the memory with xmlFree(). Note that @format = 1 provide node indenting only if xmlIndentTreeOutput = 1 or xmlKeepBlanksDefault(0) was called

@@ -831,8 +831,8 @@ A:link, A:visited, A:active { text-decoration: underline }
filename:the filename (or URL)
cur:the document
format:should formatting spaces been added
Returns:the number of bytes written or -1 in case of failure.

Function: xmlSaveFormatFileEnc

int	xmlSaveFormatFileEnc		(const char * filename, 
xmlDocPtr cur,
const char * encoding,
int format)

Dump an XML document to a file or an URL.

filename:the filename or URL to output
cur:the document being saved
encoding:the name of the encoding to use or NULL.
format:should formatting spaces be added.
Returns:the number of bytes written or -1 in case of error. Note that @format = 1 provide node indenting only if xmlIndentTreeOutput = 1 or xmlKeepBlanksDefault(0) was called

Function: xmlSaveFormatFileTo

int	xmlSaveFormatFileTo		(xmlOutputBufferPtr buf, 
xmlDocPtr cur,
const char * encoding,
int format)
-

Dump an XML document to an I/O buffer.

-
buf:an output I/O buffer
cur:the document
encoding:the encoding if any assuming the I/O layer handles the trancoding
format:should formatting spaces been added
Returns:the number of bytes written or -1 in case of failure. Note that @format = 1 provide node indenting only if xmlIndentTreeOutput = 1 or xmlKeepBlanksDefault(0) was called

Function: xmlSearchNs

xmlNsPtr	xmlSearchNs		(xmlDocPtr doc, 
xmlNodePtr node,
const xmlChar * nameSpace)
+

Dump an XML document to an I/O buffer. NOTE: the I/O buffer is closed as part of the call.

+
buf:an output I/O buffer
cur:the document
encoding:the encoding if any assuming the I/O layer handles the trancoding
format:should formatting spaces been added
Returns:the number of bytes written or -1 in case of failure.

Function: xmlSearchNs

xmlNsPtr	xmlSearchNs		(xmlDocPtr doc, 
xmlNodePtr node,
const xmlChar * nameSpace)

Search a Ns registered under a given name space for a document. recurse on the parents until it finds the defined namespace or return NULL otherwise. @nameSpace can be NULL, this is a search for the default namespace. We don't allow to cross entities boundaries. If you don't declare the namespace within those you will be in troubles !!! A warning is generated to cover this case.

doc:the document
node:the current node
nameSpace:the namespace prefix
Returns:the namespace pointer or NULL.

Function: xmlSearchNsByHref

xmlNsPtr	xmlSearchNsByHref	(xmlDocPtr doc, 
xmlNodePtr node,
const xmlChar * href)

Search a Ns aliasing a given URI. Recurse on the parents until it finds the defined namespace or return NULL otherwise.

diff --git a/doc/html/libxml-xmlwriter.html b/doc/html/libxml-xmlwriter.html index c5f205db..458262c1 100644 --- a/doc/html/libxml-xmlwriter.html +++ b/doc/html/libxml-xmlwriter.html @@ -10,7 +10,7 @@ A:link, A:visited, A:active { text-decoration: underline } Module xmlwriter from libxml2
Action against software patentsGnome2 LogoW3C LogoRed Hat Logo
Made with Libxml2 Logo

Module xmlwriter from libxml2

API Menu
API Indexes
Related links

text writing API for XML

Table of Contents

#define xmlTextWriterEndDTDAttlist
#define xmlTextWriterEndDTDElement
#define xmlTextWriterEndDTDEntity
#define xmlTextWriterWriteDocType
#define xmlTextWriterWriteProcessingInstruction
Structure xmlTextWriter
struct _xmlTextWriter + Module xmlwriter from libxml2
Action against software patentsGnome2 LogoW3C LogoRed Hat Logo
Made with Libxml2 Logo

Module xmlwriter from libxml2

API Menu
API Indexes
Related links

text writing API for XML

Table of Contents

#define xmlTextWriterWriteDocType
#define xmlTextWriterWriteProcessingInstruction
Structure xmlTextWriter
struct _xmlTextWriter The content of this structure is not made public by the API.
Typedef xmlTextWriter * xmlTextWriterPtr
 
void	xmlFreeTextWriter		(xmlTextWriterPtr writer)
@@ -24,6 +24,9 @@ The content of this structure is not made public by the API.
int	xmlTextWriterEndCDATA		(xmlTextWriterPtr writer)
int	xmlTextWriterEndComment		(xmlTextWriterPtr writer)
int	xmlTextWriterEndDTD		(xmlTextWriterPtr writer)
+
int	xmlTextWriterEndDTDAttlist	(xmlTextWriterPtr writer)
+
int	xmlTextWriterEndDTDElement	(xmlTextWriterPtr writer)
+
int	xmlTextWriterEndDTDEntity	(xmlTextWriterPtr writer)
int	xmlTextWriterEndDocument	(xmlTextWriterPtr writer)
int	xmlTextWriterEndElement		(xmlTextWriterPtr writer)
int	xmlTextWriterEndPI		(xmlTextWriterPtr writer)
@@ -54,6 +57,7 @@ The content of this structure is not made public by the API.
int	xmlTextWriterWriteDTDElement	(xmlTextWriterPtr writer, 
const xmlChar * name,
const xmlChar * content)
int	xmlTextWriterWriteDTDEntity	(xmlTextWriterPtr writer, 
int pe,
const xmlChar * name,
const xmlChar * pubid,
const xmlChar * sysid,
const xmlChar * ndataid,
const xmlChar * content)
int	xmlTextWriterWriteDTDExternalEntity	(xmlTextWriterPtr writer, 
int pe,
const xmlChar * name,
const xmlChar * pubid,
const xmlChar * sysid,
const xmlChar * ndataid)
+
int	xmlTextWriterWriteDTDExternalEntityContents	(xmlTextWriterPtr writer, 
const xmlChar * pubid,
const xmlChar * sysid,
const xmlChar * ndataid)
int	xmlTextWriterWriteDTDInternalEntity	(xmlTextWriterPtr writer, 
int pe,
const xmlChar * name,
const xmlChar * content)
int	xmlTextWriterWriteDTDNotation	(xmlTextWriterPtr writer, 
const xmlChar * name,
const xmlChar * pubid,
const xmlChar * sysid)
int	xmlTextWriterWriteElement	(xmlTextWriterPtr writer, 
const xmlChar * name,
const xmlChar * content)
@@ -89,9 +93,6 @@ The content of this structure is not made public by the API.
int	xmlTextWriterWriteVFormatRaw	(xmlTextWriterPtr writer, 
const char * format,
va_list argptr)
int	xmlTextWriterWriteVFormatString	(xmlTextWriterPtr writer, 
const char * format,
va_list argptr)

Description

-

Macro: xmlTextWriterEndDTDAttlist

#define xmlTextWriterEndDTDAttlist

This macro maps to xmlTextWriterEndDTD

-

Macro: xmlTextWriterEndDTDElement

#define xmlTextWriterEndDTDElement

This macro maps to xmlTextWriterEndDTD

-

Macro: xmlTextWriterEndDTDEntity

#define xmlTextWriterEndDTDEntity

This macro maps to xmlTextWriterEndDTD

Macro: xmlTextWriterWriteDocType

#define xmlTextWriterWriteDocType

this macro maps to xmlTextWriterWriteDTD

Macro: xmlTextWriterWriteProcessingInstruction

#define xmlTextWriterWriteProcessingInstruction

This macro maps to xmlTextWriterWritePI

Structure xmlTextWriter

Structure xmlTextWriter
struct _xmlTextWriter { @@ -118,6 +119,12 @@ The content of this structure is not made public by the API.

End the current xml coment.

writer:the xmlTextWriterPtr
Returns:the bytes written (may be 0 because of buffering) or -1 in case of error

Function: xmlTextWriterEndDTD

int	xmlTextWriterEndDTD		(xmlTextWriterPtr writer)

End an xml DTD.

+
writer:the xmlTextWriterPtr
Returns:the bytes written (may be 0 because of buffering) or -1 in case of error

Function: xmlTextWriterEndDTDAttlist

int	xmlTextWriterEndDTDAttlist	(xmlTextWriterPtr writer)
+

End an xml DTD attribute list.

+
writer:the xmlTextWriterPtr
Returns:the bytes written (may be 0 because of buffering) or -1 in case of error

Function: xmlTextWriterEndDTDElement

int	xmlTextWriterEndDTDElement	(xmlTextWriterPtr writer)
+

End an xml DTD element.

+
writer:the xmlTextWriterPtr
Returns:the bytes written (may be 0 because of buffering) or -1 in case of error

Function: xmlTextWriterEndDTDEntity

int	xmlTextWriterEndDTDEntity	(xmlTextWriterPtr writer)
+

End an xml DTD entity.

writer:the xmlTextWriterPtr
Returns:the bytes written (may be 0 because of buffering) or -1 in case of error

Function: xmlTextWriterEndDocument

int	xmlTextWriterEndDocument	(xmlTextWriterPtr writer)

End an xml document. All open elements are closed

writer:the xmlTextWriterPtr
Returns:the bytes written (may be 0 because of buffering) or -1 in case of error

Function: xmlTextWriterEndElement

int	xmlTextWriterEndElement		(xmlTextWriterPtr writer)
@@ -177,8 +184,10 @@ The content of this structure is not made public by the API.
writer:the xmlTextWriterPtr
name:the name of the DTD element
content:content of the element
Returns:the bytes written (may be 0 because of buffering) or -1 in case of error

Function: xmlTextWriterWriteDTDEntity

int	xmlTextWriterWriteDTDEntity	(xmlTextWriterPtr writer, 
int pe,
const xmlChar * name,
const xmlChar * pubid,
const xmlChar * sysid,
const xmlChar * ndataid,
const xmlChar * content)

Write a DTD entity.

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
Returns:the bytes written (may be 0 because of buffering) or -1 in case of error

Function: xmlTextWriterWriteDTDExternalEntity

int	xmlTextWriterWriteDTDExternalEntity	(xmlTextWriterPtr writer, 
int pe,
const xmlChar * name,
const xmlChar * pubid,
const xmlChar * sysid,
const xmlChar * ndataid)
-

Write a DTD internal entity.

-
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.
Returns:the bytes written (may be 0 because of buffering) or -1 in case of error

Function: xmlTextWriterWriteDTDInternalEntity

int	xmlTextWriterWriteDTDInternalEntity	(xmlTextWriterPtr writer, 
int pe,
const xmlChar * name,
const xmlChar * content)
+

Write a DTD external entity. The entity must have been started with xmlTextWriterStartDTDEntity

+
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.
Returns:the bytes written (may be 0 because of buffering) or -1 in case of error

Function: xmlTextWriterWriteDTDExternalEntityContents

int	xmlTextWriterWriteDTDExternalEntityContents	(xmlTextWriterPtr writer, 
const xmlChar * pubid,
const xmlChar * sysid,
const xmlChar * ndataid)
+

Write the contents of a DTD external entity.

+
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.
Returns:the bytes written (may be 0 because of buffering) or -1 in case of error

Function: xmlTextWriterWriteDTDInternalEntity

int	xmlTextWriterWriteDTDInternalEntity	(xmlTextWriterPtr writer, 
int pe,
const xmlChar * name,
const xmlChar * content)

Write a DTD internal entity.

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
Returns:the bytes written (may be 0 because of buffering) or -1 in case of error

Function: xmlTextWriterWriteDTDNotation

int	xmlTextWriterWriteDTDNotation	(xmlTextWriterPtr writer, 
const xmlChar * name,
const xmlChar * pubid,
const xmlChar * sysid)

Write a DTD entity.

diff --git a/doc/libxml2-api.xml b/doc/libxml2-api.xml index 1162e1a4..3546b0c8 100644 --- a/doc/libxml2-api.xml +++ b/doc/libxml2-api.xml @@ -2709,20 +2709,17 @@ text writing API for XML Alfred Mickautsch <alfred@mickautsch.de> - - - - + - + @@ -2734,10 +2731,11 @@ - + + @@ -2745,9 +2743,11 @@ + + @@ -2757,9 +2757,9 @@ - - + + @@ -2774,6 +2774,7 @@ + @@ -3550,15 +3551,6 @@ Macro for compatibility naming layer with libxml1. Maps to "children". - - This macro maps to xmlTextWriterEndDTD - - - This macro maps to xmlTextWriterEndDTD - - - This macro maps to xmlTextWriterEndDTD - this macro maps to xmlTextWriterWriteDTD @@ -7227,7 +7219,7 @@ actually an xmlCharEncoding'/> Do a copy of the document info. If recursive, the content tree will be copied too as well as DTD, namespaces and entities. - + Do a copy of the dtd. @@ -7274,7 +7266,7 @@ actually an xmlCharEncoding'/> Do a copy of the node. - + Do a recursive copy of the node list. @@ -7599,7 +7591,7 @@ actually an xmlCharEncoding'/> - + Dump an XML document to an open FILE. @@ -10989,8 +10981,8 @@ actually an xmlCharEncoding'/> - Dump an XML document to an I/O buffer. - + Dump an XML document to an I/O buffer. NOTE: the I/O buffer is closed as part of the call. + @@ -12015,6 +12007,21 @@ actually an xmlCharEncoding'/> + + End an xml DTD attribute list. + + + + + End an xml DTD element. + + + + + End an xml DTD entity. + + + End an xml document. All open elements are closed @@ -12210,7 +12217,7 @@ actually an xmlCharEncoding'/> - Write a DTD internal entity. + Write a DTD external entity. The entity must have been started with xmlTextWriterStartDTDEntity @@ -12219,6 +12226,14 @@ actually an xmlCharEncoding'/> + + Write the contents of a DTD external entity. + + + + + + Write a DTD internal entity. diff --git a/doc/libxml2-refs.xml b/doc/libxml2-refs.xml index 0bdf8a4f..da0f2e22 100644 --- a/doc/libxml2-refs.xml +++ b/doc/libxml2-refs.xml @@ -2350,6 +2350,7 @@ + @@ -5264,6 +5265,7 @@ + @@ -6868,6 +6870,7 @@ + @@ -8624,6 +8627,9 @@ + + + @@ -8654,6 +8660,7 @@ + @@ -11493,6 +11500,7 @@ + @@ -13003,6 +13011,9 @@ + + + @@ -13992,6 +14003,7 @@ + @@ -14136,7 +14148,6 @@ - @@ -16232,6 +16243,7 @@ + @@ -16353,6 +16365,10 @@ + + + + @@ -16849,6 +16865,7 @@ + @@ -17144,36 +17161,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -17248,6 +17235,7 @@ + @@ -17725,6 +17713,7 @@ + @@ -19921,6 +19910,7 @@ + @@ -20298,7 +20288,6 @@ - @@ -21206,9 +21195,6 @@ - - - @@ -21279,9 +21265,6 @@ - - - @@ -21643,6 +21626,8 @@ + + @@ -22941,6 +22926,8 @@ + + @@ -22983,7 +22970,6 @@ - @@ -24543,6 +24529,9 @@ + + + @@ -26441,7 +26430,6 @@ - @@ -26523,7 +26511,6 @@ - @@ -26885,10 +26872,8 @@ - - - - + + @@ -27070,6 +27055,7 @@ + diff --git a/include/libxml/xmlwriter.h b/include/libxml/xmlwriter.h index 37cf40c6..f1e1fd84 100644 --- a/include/libxml/xmlwriter.h +++ b/include/libxml/xmlwriter.h @@ -37,8 +37,8 @@ extern "C" { XMLPUBFUN xmlTextWriterPtr XMLCALL xmlNewTextWriterDoc(xmlDocPtr * doc, int compression); XMLPUBFUN xmlTextWriterPtr XMLCALL - xmlNewTextWriterTree(xmlDocPtr doc, - xmlNodePtr node, int compression); + xmlNewTextWriterTree(xmlDocPtr doc, xmlNodePtr node, + int compression); XMLPUBFUN void XMLCALL xmlFreeTextWriter(xmlTextWriterPtr writer); /* @@ -54,14 +54,14 @@ extern "C" { const char *version, const char *encoding, const char *standalone); - XMLPUBFUN int XMLCALL - xmlTextWriterEndDocument(xmlTextWriterPtr writer); + XMLPUBFUN int XMLCALL xmlTextWriterEndDocument(xmlTextWriterPtr + writer); /* * Comments */ - XMLPUBFUN int XMLCALL - xmlTextWriterStartComment(xmlTextWriterPtr writer); + XMLPUBFUN int XMLCALL xmlTextWriterStartComment(xmlTextWriterPtr + writer); XMLPUBFUN int XMLCALL xmlTextWriterEndComment(xmlTextWriterPtr writer); XMLPUBFUN int XMLCALL xmlTextWriterWriteFormatComment(xmlTextWriterPtr writer, @@ -70,9 +70,10 @@ extern "C" { xmlTextWriterWriteVFormatComment(xmlTextWriterPtr writer, const char *format, va_list argptr); - XMLPUBFUN int XMLCALL - xmlTextWriterWriteComment(xmlTextWriterPtr writer, - const xmlChar * content); + XMLPUBFUN int XMLCALL xmlTextWriterWriteComment(xmlTextWriterPtr + writer, + const xmlChar * + content); /* * Elements @@ -80,14 +81,16 @@ extern "C" { XMLPUBFUN int XMLCALL xmlTextWriterStartElement(xmlTextWriterPtr writer, const xmlChar * name); - XMLPUBFUN int XMLCALL - xmlTextWriterStartElementNS(xmlTextWriterPtr writer, - const xmlChar * prefix, - const xmlChar * name, - const xmlChar * namespaceURI); + XMLPUBFUN int XMLCALL xmlTextWriterStartElementNS(xmlTextWriterPtr + writer, + const xmlChar * + prefix, + const xmlChar * name, + const xmlChar * + namespaceURI); XMLPUBFUN int XMLCALL xmlTextWriterEndElement(xmlTextWriterPtr writer); - XMLPUBFUN int XMLCALL - xmlTextWriterFullEndElement(xmlTextWriterPtr writer); + XMLPUBFUN int XMLCALL xmlTextWriterFullEndElement(xmlTextWriterPtr + writer); /* * Elements conveniency functions @@ -101,10 +104,11 @@ extern "C" { const xmlChar * name, const char *format, va_list argptr); - XMLPUBFUN int XMLCALL - xmlTextWriterWriteElement(xmlTextWriterPtr writer, - const xmlChar * name, - const xmlChar * content); + XMLPUBFUN int XMLCALL xmlTextWriterWriteElement(xmlTextWriterPtr + writer, + const xmlChar * name, + const xmlChar * + content); XMLPUBFUN int XMLCALL xmlTextWriterWriteFormatElementNS(xmlTextWriterPtr writer, const xmlChar * prefix, @@ -118,12 +122,15 @@ extern "C" { const xmlChar * namespaceURI, const char *format, va_list argptr); - XMLPUBFUN int XMLCALL - xmlTextWriterWriteElementNS(xmlTextWriterPtr writer, - const xmlChar * prefix, - const xmlChar * name, - const xmlChar * namespaceURI, - const xmlChar * content); + XMLPUBFUN int XMLCALL xmlTextWriterWriteElementNS(xmlTextWriterPtr + writer, + const xmlChar * + prefix, + const xmlChar * name, + const xmlChar * + namespaceURI, + const xmlChar * + content); /* * Text @@ -140,22 +147,24 @@ extern "C" { XMLPUBFUN int XMLCALL xmlTextWriterWriteRaw(xmlTextWriterPtr writer, const xmlChar * content); - XMLPUBFUN int XMLCALL - xmlTextWriterWriteFormatString(xmlTextWriterPtr writer, - const char *format, ...); - XMLPUBFUN int XMLCALL - xmlTextWriterWriteVFormatString(xmlTextWriterPtr writer, - const char *format, - va_list argptr); - XMLPUBFUN int XMLCALL - xmlTextWriterWriteString(xmlTextWriterPtr writer, - const xmlChar * content); - XMLPUBFUN int XMLCALL - xmlTextWriterWriteBase64(xmlTextWriterPtr writer, - const char *data, int start, int len); - XMLPUBFUN int XMLCALL - xmlTextWriterWriteBinHex(xmlTextWriterPtr writer, - const char *data, int start, int len); + XMLPUBFUN int XMLCALL xmlTextWriterWriteFormatString(xmlTextWriterPtr + writer, + const char + *format, ...); + XMLPUBFUN int XMLCALL xmlTextWriterWriteVFormatString(xmlTextWriterPtr + writer, + const char + *format, + va_list argptr); + XMLPUBFUN int XMLCALL xmlTextWriterWriteString(xmlTextWriterPtr writer, + const xmlChar * + content); + XMLPUBFUN int XMLCALL xmlTextWriterWriteBase64(xmlTextWriterPtr writer, + const char *data, + int start, int len); + XMLPUBFUN int XMLCALL xmlTextWriterWriteBinHex(xmlTextWriterPtr writer, + const char *data, + int start, int len); /* * Attributes @@ -163,13 +172,16 @@ extern "C" { XMLPUBFUN int XMLCALL xmlTextWriterStartAttribute(xmlTextWriterPtr writer, const xmlChar * name); - XMLPUBFUN int XMLCALL - xmlTextWriterStartAttributeNS(xmlTextWriterPtr writer, - const xmlChar * prefix, - const xmlChar * name, - const xmlChar * namespaceURI); - XMLPUBFUN int XMLCALL - xmlTextWriterEndAttribute(xmlTextWriterPtr writer); + XMLPUBFUN int XMLCALL xmlTextWriterStartAttributeNS(xmlTextWriterPtr + writer, + const xmlChar * + prefix, + const xmlChar * + name, + const xmlChar * + namespaceURI); + XMLPUBFUN int XMLCALL xmlTextWriterEndAttribute(xmlTextWriterPtr + writer); /* * Attributes conveniency functions @@ -183,10 +195,11 @@ extern "C" { const xmlChar * name, const char *format, va_list argptr); - XMLPUBFUN int XMLCALL - xmlTextWriterWriteAttribute(xmlTextWriterPtr writer, - const xmlChar * name, - const xmlChar * content); + XMLPUBFUN int XMLCALL xmlTextWriterWriteAttribute(xmlTextWriterPtr + writer, + const xmlChar * name, + const xmlChar * + content); XMLPUBFUN int XMLCALL xmlTextWriterWriteFormatAttributeNS(xmlTextWriterPtr writer, const xmlChar * prefix, @@ -200,12 +213,16 @@ extern "C" { const xmlChar * namespaceURI, const char *format, va_list argptr); - XMLPUBFUN int XMLCALL - xmlTextWriterWriteAttributeNS(xmlTextWriterPtr writer, - const xmlChar * prefix, - const xmlChar * name, - const xmlChar * namespaceURI, - const xmlChar * content); + XMLPUBFUN int XMLCALL xmlTextWriterWriteAttributeNS(xmlTextWriterPtr + writer, + const xmlChar * + prefix, + const xmlChar * + name, + const xmlChar * + namespaceURI, + const xmlChar * + content); /* * PI's @@ -302,13 +319,8 @@ extern "C" { XMLPUBFUN int XMLCALL xmlTextWriterStartDTDElement(xmlTextWriterPtr writer, const xmlChar * name); - -/** - * xmlTextWriterEndDTDElement: - * - * This macro maps to xmlTextWriterEndDTD - */ -#define xmlTextWriterEndDTDElement xmlTextWriterEndDTD + XMLPUBFUN int XMLCALL xmlTextWriterEndDTDElement(xmlTextWriterPtr + writer); /* * DTD element definition conveniency functions @@ -322,10 +334,12 @@ extern "C" { const xmlChar * name, const char *format, va_list argptr); - XMLPUBFUN int XMLCALL - xmlTextWriterWriteDTDElement(xmlTextWriterPtr writer, - const xmlChar * name, - const xmlChar * content); + XMLPUBFUN int XMLCALL xmlTextWriterWriteDTDElement(xmlTextWriterPtr + writer, + const xmlChar * + name, + const xmlChar * + content); /* * DTD attribute list definition @@ -333,13 +347,8 @@ extern "C" { XMLPUBFUN int XMLCALL xmlTextWriterStartDTDAttlist(xmlTextWriterPtr writer, const xmlChar * name); - -/** - * xmlTextWriterEndDTDAttlist: - * - * This macro maps to xmlTextWriterEndDTD - */ -#define xmlTextWriterEndDTDAttlist xmlTextWriterEndDTD + XMLPUBFUN int XMLCALL xmlTextWriterEndDTDAttlist(xmlTextWriterPtr + writer); /* * DTD attribute list definition conveniency functions @@ -353,10 +362,12 @@ extern "C" { const xmlChar * name, const char *format, va_list argptr); - XMLPUBFUN int XMLCALL - xmlTextWriterWriteDTDAttlist(xmlTextWriterPtr writer, - const xmlChar * name, - const xmlChar * content); + XMLPUBFUN int XMLCALL xmlTextWriterWriteDTDAttlist(xmlTextWriterPtr + writer, + const xmlChar * + name, + const xmlChar * + content); /* * DTD entity definition @@ -364,13 +375,8 @@ extern "C" { XMLPUBFUN int XMLCALL xmlTextWriterStartDTDEntity(xmlTextWriterPtr writer, int pe, const xmlChar * name); - -/** - * xmlTextWriterEndDTDEntity: - * - * This macro maps to xmlTextWriterEndDTD - */ -#define xmlTextWriterEndDTDEntity xmlTextWriterEndDTD + XMLPUBFUN int XMLCALL xmlTextWriterEndDTDEntity(xmlTextWriterPtr + writer); /* * DTD entity definition conveniency functions @@ -399,13 +405,23 @@ extern "C" { const xmlChar * sysid, const xmlChar * ndataid); XMLPUBFUN int XMLCALL - xmlTextWriterWriteDTDEntity(xmlTextWriterPtr writer, - int pe, - const xmlChar * name, - const xmlChar * pubid, - const xmlChar * sysid, - const xmlChar * ndataid, - const xmlChar * content); + xmlTextWriterWriteDTDExternalEntityContents(xmlTextWriterPtr + writer, + const xmlChar * pubid, + const xmlChar * sysid, + const xmlChar * + ndataid); + XMLPUBFUN int XMLCALL xmlTextWriterWriteDTDEntity(xmlTextWriterPtr + writer, int pe, + const xmlChar * name, + const xmlChar * + pubid, + const xmlChar * + sysid, + const xmlChar * + ndataid, + const xmlChar * + content); /* * DTD notation definition diff --git a/parser.c b/parser.c index 4350f12a..49ed8577 100644 --- a/parser.c +++ b/parser.c @@ -9949,7 +9949,7 @@ xmlIOParseDTD(xmlSAXHandlerPtr sax, xmlParserInputBufferPtr input, if (ctxt->sax != NULL) xmlFree(ctxt->sax); ctxt->sax = sax; - ctxt->userData = NULL; + ctxt->userData = ctxt; } xmlDetectSAX2(ctxt); @@ -12025,25 +12025,12 @@ xmlDoRead(xmlParserCtxtPtr ctxt, const char *URL, const char *encoding, else { ret = NULL; if (ctxt->myDoc != NULL) { - if ((ctxt->dictNames) && - (ctxt->myDoc->dict == ctxt->dict)) - xmlDictReference(ctxt->dict); xmlFreeDoc(ctxt->myDoc); } } ctxt->myDoc = NULL; if (!reuse) { - if ((ctxt->dictNames) && - (ret != NULL) && - (ret->dict == ctxt->dict)) - ctxt->dict = NULL; xmlFreeParserCtxt(ctxt); - } else { - /* Must duplicate the reference to the dictionary */ - if ((ctxt->dictNames) && - (ret != NULL) && - (ret->dict == ctxt->dict)) - xmlDictReference(ctxt->dict); } return (ret); diff --git a/python/libxml2class.txt b/python/libxml2class.txt index ae0e658b..1df60379 100644 --- a/python/libxml2class.txt +++ b/python/libxml2class.txt @@ -632,6 +632,57 @@ Class xmlDoc(xmlNode) # functions from module xpointer xpointerNewContext() +Class xpathContext() + # accessors + contextDoc() + contextNode() + contextPosition() + contextSize() + function() + functionURI() + setContextDoc() + setContextNode() + + # functions from module python + registerXPathFunction() + + # functions from module xpath + xpathEval() + xpathEvalExpression() + xpathFreeContext() + + # functions from module xpathInternals + xpathNewParserContext() + xpathNsLookup() + xpathRegisterAllFunctions() + xpathRegisterNs() + xpathRegisteredFuncsCleanup() + xpathRegisteredNsCleanup() + xpathRegisteredVariablesCleanup() + xpathVariableLookup() + xpathVariableLookupNS() + + # functions from module xpointer + xpointerEval() + + +Class xmlAttribute(xmlNode) +Class catalog() + + # functions from module catalog + add() + catalogIsEmpty() + convertSGMLCatalog() + dump() + freeCatalog() + remove() + resolve() + resolvePublic() + resolveSystem() + resolveURI() + + +Class xmlElement(xmlNode) Class xmlAttr(xmlNode) @@ -650,6 +701,62 @@ Class xmlAttr(xmlNode) # functions from module valid removeID() removeRef() + + +Class xmlTextReader(xmlTextReaderCore) + + # functions from module xmlreader + AttributeCount() + BaseUri() + Close() + CurrentDoc() + CurrentNode() + Depth() + Expand() + GetAttribute() + GetAttributeNo() + GetAttributeNs() + GetParserProp() + GetRemainder() + HasAttributes() + HasValue() + IsDefault() + IsEmptyElement() + IsValid() + LocalName() + LookupNamespace() + MoveToAttribute() + MoveToAttributeNo() + MoveToAttributeNs() + MoveToElement() + MoveToFirstAttribute() + MoveToNextAttribute() + Name() + NamespaceUri() + NewDoc() + NewFd() + NewFile() + NewMemory() + NewWalker() + Next() + NextSibling() + NodeType() + Normalization() + Prefix() + Preserve() + QuoteChar() + Read() + ReadAttributeValue() + ReadInnerXml() + ReadOuterXml() + ReadState() + ReadString() + RelaxNGSetSchema() + RelaxNGValidate() + SetParserProp() + String() + Value() + XmlLang() Class xmlReg() # functions from module xmlregexp @@ -657,6 +764,34 @@ Class xmlReg() regexpFreeRegexp() regexpIsDeterminist() regexpPrint() + + +Class xmlEntity(xmlNode) + + # functions from module parserInternals + handleEntity() +Class relaxNgSchema() + + # functions from module relaxng + relaxNGDump() + relaxNGDumpTree() + relaxNGFree() + relaxNGNewValidCtxt() + + # functions from module xmlreader + RelaxNGSetSchema() +Class Error() + # accessors + code() + domain() + file() + level() + line() + message() + + # functions from module xmlerror + copyError() + resetError() Class relaxNgValidCtxt() # functions from module relaxng @@ -665,6 +800,73 @@ Class relaxNgValidCtxt() relaxNGValidatePopElement() relaxNGValidatePushCData() relaxNGValidatePushElement() +Class xpathParserContext() + # accessors + context() + + # functions from module xpathInternals + xpathAddValues() + xpathBooleanFunction() + xpathCeilingFunction() + xpathCompareValues() + xpathConcatFunction() + xpathContainsFunction() + xpathCountFunction() + xpathDivValues() + xpathEqualValues() + xpathErr() + xpathEvalExpr() + xpathFalseFunction() + xpathFloorFunction() + xpathFreeParserContext() + xpathIdFunction() + xpathLangFunction() + xpathLastFunction() + xpathLocalNameFunction() + xpathModValues() + xpathMultValues() + xpathNamespaceURIFunction() + xpathNextAncestor() + xpathNextAncestorOrSelf() + xpathNextAttribute() + xpathNextChild() + xpathNextDescendant() + xpathNextDescendantOrSelf() + xpathNextFollowing() + xpathNextFollowingSibling() + xpathNextNamespace() + xpathNextParent() + xpathNextPreceding() + xpathNextPrecedingSibling() + xpathNextSelf() + xpathNormalizeFunction() + xpathNotEqualValues() + xpathNotFunction() + xpathNumberFunction() + xpathParseNCName() + xpathParseName() + xpathPopBoolean() + xpathPopNumber() + xpathPopString() + xpathPositionFunction() + xpathRoot() + xpathRoundFunction() + xpathStartsWithFunction() + xpathStringFunction() + xpathStringLengthFunction() + xpathSubValues() + xpathSubstringAfterFunction() + xpathSubstringBeforeFunction() + xpathSubstringFunction() + xpathSumFunction() + xpathTranslateFunction() + xpathTrueFunction() + xpathValueFlipSign() + xpatherror() + + # functions from module xpointer + xpointerEvalRangePredicate() + xpointerRangeToFunction() Class parserCtxt(parserCtxtCore) @@ -772,92 +974,6 @@ Class xmlDtd(xmlNode) dtdElementDesc() dtdQAttrDesc() dtdQElementDesc() -Class relaxNgParserCtxt() - - # functions from module relaxng - relaxNGFreeParserCtxt() - relaxNGParse() - relaxParserSetFlag() -Class xpathParserContext() - # accessors - context() - - # functions from module xpathInternals - xpathAddValues() - xpathBooleanFunction() - xpathCeilingFunction() - xpathCompareValues() - xpathConcatFunction() - xpathContainsFunction() - xpathCountFunction() - xpathDivValues() - xpathEqualValues() - xpathErr() - xpathEvalExpr() - xpathFalseFunction() - xpathFloorFunction() - xpathFreeParserContext() - xpathIdFunction() - xpathLangFunction() - xpathLastFunction() - xpathLocalNameFunction() - xpathModValues() - xpathMultValues() - xpathNamespaceURIFunction() - xpathNextAncestor() - xpathNextAncestorOrSelf() - xpathNextAttribute() - xpathNextChild() - xpathNextDescendant() - xpathNextDescendantOrSelf() - xpathNextFollowing() - xpathNextFollowingSibling() - xpathNextNamespace() - xpathNextParent() - xpathNextPreceding() - xpathNextPrecedingSibling() - xpathNextSelf() - xpathNormalizeFunction() - xpathNotEqualValues() - xpathNotFunction() - xpathNumberFunction() - xpathParseNCName() - xpathParseName() - xpathPopBoolean() - xpathPopNumber() - xpathPopString() - xpathPositionFunction() - xpathRoot() - xpathRoundFunction() - xpathStartsWithFunction() - xpathStringFunction() - xpathStringLengthFunction() - xpathSubValues() - xpathSubstringAfterFunction() - xpathSubstringBeforeFunction() - xpathSubstringFunction() - xpathSumFunction() - xpathTranslateFunction() - xpathTrueFunction() - xpathValueFlipSign() - xpatherror() - - # functions from module xpointer - xpointerEvalRangePredicate() - xpointerRangeToFunction() -Class catalog() - - # functions from module catalog - add() - catalogIsEmpty() - convertSGMLCatalog() - dump() - freeCatalog() - remove() - resolve() - resolvePublic() - resolveSystem() - resolveURI() Class xmlNs(xmlNode) @@ -881,6 +997,42 @@ Class xmlNs(xmlNode) # functions from module xpathInternals xpathNodeSetFreeNs() + + +Class inputBuffer(ioReadWrapper) + + # functions from module xmlIO + freeParserInputBuffer() + grow() + push() + read() + + # functions from module xmlreader + newTextReader() +Class relaxNgParserCtxt() + + # functions from module relaxng + relaxNGFreeParserCtxt() + relaxNGParse() + relaxParserSetFlag() + + +Class outputBuffer(ioWriteWrapper) + + # functions from module HTMLtree + htmlDocContentDumpFormatOutput() + htmlDocContentDumpOutput() + htmlNodeDumpFormatOutput() + htmlNodeDumpOutput() + + # functions from module tree + nodeDumpOutput() + saveFileTo() + saveFormatFileTo() + + # functions from module xmlIO + write() + writeString() Class xmlTextReaderLocator() # functions from module xmlreader @@ -912,155 +1064,3 @@ Class URI() parseURIReference() printURI() saveUri() - - -Class xmlAttribute(xmlNode) -Class xpathContext() - # accessors - contextDoc() - contextNode() - contextPosition() - contextSize() - function() - functionURI() - setContextDoc() - setContextNode() - - # functions from module python - registerXPathFunction() - - # functions from module xpath - xpathEval() - xpathEvalExpression() - xpathFreeContext() - - # functions from module xpathInternals - xpathNewParserContext() - xpathNsLookup() - xpathRegisterAllFunctions() - xpathRegisterNs() - xpathRegisteredFuncsCleanup() - xpathRegisteredNsCleanup() - xpathRegisteredVariablesCleanup() - xpathVariableLookup() - xpathVariableLookupNS() - - # functions from module xpointer - xpointerEval() - - -Class xmlElement(xmlNode) - - -Class xmlTextReader(xmlTextReaderCore) - - # functions from module xmlreader - AttributeCount() - BaseUri() - Close() - CurrentDoc() - CurrentNode() - Depth() - Expand() - GetAttribute() - GetAttributeNo() - GetAttributeNs() - GetParserProp() - GetRemainder() - HasAttributes() - HasValue() - IsDefault() - IsEmptyElement() - IsValid() - LocalName() - LookupNamespace() - MoveToAttribute() - MoveToAttributeNo() - MoveToAttributeNs() - MoveToElement() - MoveToFirstAttribute() - MoveToNextAttribute() - Name() - NamespaceUri() - NewDoc() - NewFd() - NewFile() - NewMemory() - NewWalker() - Next() - NextSibling() - NodeType() - Normalization() - Prefix() - Preserve() - QuoteChar() - Read() - ReadAttributeValue() - ReadInnerXml() - ReadOuterXml() - ReadState() - ReadString() - RelaxNGSetSchema() - RelaxNGValidate() - SetParserProp() - String() - Value() - XmlLang() - - -Class xmlEntity(xmlNode) - - # functions from module parserInternals - handleEntity() -Class Error() - # accessors - code() - domain() - file() - level() - line() - message() - - # functions from module xmlerror - copyError() - resetError() -Class relaxNgSchema() - - # functions from module relaxng - relaxNGDump() - relaxNGDumpTree() - relaxNGFree() - relaxNGNewValidCtxt() - - # functions from module xmlreader - RelaxNGSetSchema() - - -Class inputBuffer(ioReadWrapper) - - # functions from module xmlIO - freeParserInputBuffer() - grow() - push() - read() - - # functions from module xmlreader - newTextReader() - - -Class outputBuffer(ioWriteWrapper) - - # functions from module HTMLtree - htmlDocContentDumpFormatOutput() - htmlDocContentDumpOutput() - htmlNodeDumpFormatOutput() - htmlNodeDumpOutput() - - # functions from module tree - nodeDumpOutput() - saveFileTo() - saveFormatFileTo() - - # functions from module xmlIO - write() - writeString() diff --git a/win32/libxml2.def.src b/win32/libxml2.def.src index 1d4e9d5d..3faab29f 100644 --- a/win32/libxml2.def.src +++ b/win32/libxml2.def.src @@ -1450,12 +1450,20 @@ xmlSAXParseMemoryWithData xmlSAXUserParseFile xmlSAXUserParseMemory xmlSAXVersion +xmlSaveClose +xmlSaveDoc xmlSaveFile xmlSaveFileEnc xmlSaveFileTo +xmlSaveFlush xmlSaveFormatFile xmlSaveFormatFileEnc xmlSaveFormatFileTo +xmlSaveToBuffer +xmlSaveToFd +xmlSaveToFilename +xmlSaveToIO +xmlSaveTree xmlSaveUri xmlScanName #ifdef LIBXML_SCHEMAS_ENABLED @@ -1692,6 +1700,9 @@ xmlTextWriterEndAttribute xmlTextWriterEndCDATA xmlTextWriterEndComment xmlTextWriterEndDTD +xmlTextWriterEndDTDAttlist +xmlTextWriterEndDTDElement +xmlTextWriterEndDTDEntity xmlTextWriterEndDocument xmlTextWriterEndElement xmlTextWriterEndPI @@ -1722,6 +1733,7 @@ xmlTextWriterWriteDTDAttlist xmlTextWriterWriteDTDElement xmlTextWriterWriteDTDEntity xmlTextWriterWriteDTDExternalEntity +xmlTextWriterWriteDTDExternalEntityContents xmlTextWriterWriteDTDInternalEntity xmlTextWriterWriteDTDNotation xmlTextWriterWriteElement diff --git a/xinclude.c b/xinclude.c index 05e05ed5..8f8b8183 100644 --- a/xinclude.c +++ b/xinclude.c @@ -453,19 +453,11 @@ xmlXIncludeParseFile(xmlXIncludeCtxtPtr ctxt, const char *URL) { if (pctxt->wellFormed) { ret = pctxt->myDoc; - xmlDictReference(pctxt->dict); } else { ret = NULL; - if (pctxt->myDoc != NULL) { - if ((ctxt->doc != NULL) && (ctxt->doc->dict != NULL) && - (pctxt->myDoc->dict == ctxt->doc->dict)) - xmlDictReference(ctxt->doc->dict); - else if ((pctxt->dict != NULL) && - (pctxt->dict == pctxt->myDoc->dict)) - xmlDictReference(pctxt->dict); + if (pctxt->myDoc != NULL) xmlFreeDoc(pctxt->myDoc); - } pctxt->myDoc = NULL; } xmlFreeParserCtxt(pctxt); diff --git a/xmlIO.c b/xmlIO.c index 0225aa05..8c4b68fd 100644 --- a/xmlIO.c +++ b/xmlIO.c @@ -785,12 +785,14 @@ xmlFileClose (void * context) { int ret; fil = (FILE *) context; + if ((fil == stdout) || (fil == stderr)) { + ret = fflush(fil); + if (ret < 0) + xmlIOErr(0, "fflush()"); + return(0); + } if (fil == stdin) return(0); - if (fil == stdout) - return(0); - if (fil == stderr) - return(0); ret = ( fclose((FILE *) context) == EOF ) ? -1 : 0; if (ret < 0) xmlIOErr(0, "fclose()"); diff --git a/xmllint.c b/xmllint.c index 5488dfd7..fd2eb8fd 100644 --- a/xmllint.c +++ b/xmllint.c @@ -874,6 +874,7 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { if (res > 0) { ctxt = xmlCreatePushParserCtxt(NULL, NULL, chars, res, filename); + xmlCtxtUseOptions(ctxt, options); while ((res = fread(chars, 1, size, f)) > 0) { xmlParseChunk(ctxt, chars, res, 0); } diff --git a/xmlreader.c b/xmlreader.c index 8a533a28..e1c2ef8a 100644 --- a/xmlreader.c +++ b/xmlreader.c @@ -496,6 +496,7 @@ xmlTextReaderFreeDoc(xmlTextReaderPtr reader, xmlDocPtr cur) { if (cur->encoding != NULL) xmlFree((char *) cur->encoding); if (cur->oldNs != NULL) xmlFreeNsList(cur->oldNs); if (cur->URL != NULL) xmlFree((char *) cur->URL); + if (cur->dict != NULL) xmlDictFree(cur->dict); xmlFree(cur); } @@ -3649,9 +3650,6 @@ xmlTextReaderCurrentDoc(xmlTextReaderPtr reader) { return(NULL); reader->preserve = 1; - if ((reader->ctxt->myDoc->dict != NULL) && - (reader->ctxt->myDoc->dict == reader->ctxt->dict)) - xmlDictReference(reader->ctxt->dict); return(reader->ctxt->myDoc); } @@ -4178,8 +4176,6 @@ xmlTextReaderSetup(xmlTextReaderPtr reader, xmlParserInputBufferPtr buf; xmlCharEncoding enc = XML_CHAR_ENCODING_NONE; - if (reader->ctxt->myDoc != NULL) - xmlDictReference(reader->ctxt->myDoc->dict); xmlCtxtReset(reader->ctxt); buf = xmlAllocParserInputBuffer(enc); if (buf == NULL) return(-1); diff --git a/xmlschemas.c b/xmlschemas.c index 3a3602f0..192cfe87 100644 --- a/xmlschemas.c +++ b/xmlschemas.c @@ -374,8 +374,8 @@ xmlSchemaNewSchema(xmlSchemaParserCtxtPtr ctxt) return (NULL); } memset(ret, 0, sizeof(xmlSchema)); - xmlDictReference(ctxt->dict); ret->dict = ctxt->dict; + xmlDictReference(ret->dict); return (ret); } diff --git a/xmlwriter.c b/xmlwriter.c index 43e5f63d..e5c7e5fc 100644 --- a/xmlwriter.c +++ b/xmlwriter.c @@ -38,9 +38,13 @@ typedef enum { XML_TEXTWRITER_DTD, XML_TEXTWRITER_DTD_TEXT, XML_TEXTWRITER_DTD_ELEM, + XML_TEXTWRITER_DTD_ELEM_TEXT, XML_TEXTWRITER_DTD_ATTL, - XML_TEXTWRITER_DTD_ENTY, - XML_TEXTWRITER_COMMENT + XML_TEXTWRITER_DTD_ATTL_TEXT, + XML_TEXTWRITER_DTD_ENTY, /* entity */ + XML_TEXTWRITER_DTD_ENTY_TEXT, + XML_TEXTWRITER_DTD_PENT, /* parameter entity */ + XML_TEXTWRITER_COMMENT, } xmlTextWriterState; typedef struct _xmlTextWriterStackEntry xmlTextWriterStackEntry; @@ -87,6 +91,9 @@ static int xmlOutputBufferWriteBase64(xmlOutputBufferPtr out, int len, const unsigned char *data); static void xmlTextWriterStartDocumentCallback(void *ctx); static int xmlTextWriterWriteIndent(xmlTextWriterPtr writer); +static int + xmlTextWriterHandleStateDependencies(xmlTextWriterPtr writer, + xmlTextWriterStackEntry * p); /** * xmlNewTextWriter: @@ -127,7 +134,7 @@ xmlNewTextWriter(xmlOutputBufferPtr out) if (ret->nsstack == NULL) { xmlGenericError(xmlGenericErrorContext, "xmlNewTextWriter : out of memory!\n"); - xmlFree(ret->nodes); + xmlListDelete(ret->nodes); xmlFree(ret); return NULL; } @@ -136,8 +143,14 @@ xmlNewTextWriter(xmlOutputBufferPtr out) ret->ichar = xmlStrdup(BAD_CAST " "); ret->qchar = '"'; - if (!ret->ichar) + if (!ret->ichar) { + xmlListDelete(ret->nodes); + xmlListDelete(ret->nsstack); + xmlFree(ret); + xmlGenericError(xmlGenericErrorContext, + "xmlNewTextWriter : out of memory!\n"); return NULL; + } return ret; } @@ -233,6 +246,12 @@ xmlNewTextWriterPushParser(xmlParserCtxtPtr ctxt, xmlTextWriterPtr ret; xmlOutputBufferPtr out; + if (ctxt == NULL) { + xmlGenericError(xmlGenericErrorContext, + "xmlNewTextWriterPushParser : invalid context!\n"); + return NULL; + } + out = xmlOutputBufferCreateIO((xmlOutputWriteCallback) xmlTextWriterWriteDocCallback, (xmlOutputCloseCallback) @@ -301,8 +320,10 @@ xmlNewTextWriterDoc(xmlDocPtr * doc, int compression) return NULL; } - *doc = ctxt->myDoc; - xmlSetDocCompressMode(*doc, compression); + xmlSetDocCompressMode(ctxt->myDoc, compression); + + if (doc != NULL) + *doc = ctxt->myDoc; return ret; } @@ -326,6 +347,8 @@ xmlNewTextWriterTree(xmlDocPtr doc, xmlNodePtr node, int compression) xmlParserCtxtPtr ctxt; if (doc == NULL) { + xmlGenericError(xmlGenericErrorContext, + "xmlNewTextWriterTree : invalid document tree!\n"); return NULL; } @@ -342,16 +365,17 @@ xmlNewTextWriterTree(xmlDocPtr doc, xmlNodePtr node, int compression) return NULL; } - ctxt->myDoc = doc; - ctxt->node = node; - ret = xmlNewTextWriterPushParser(ctxt, compression); if (ret == NULL) { + xmlFreeParserCtxt(ctxt); xmlGenericError(xmlGenericErrorContext, "xmlNewTextWriterDoc : error at xmlNewTextWriterPushParser!\n"); return NULL; } + ctxt->myDoc = doc; + ctxt->node = node; + xmlSetDocCompressMode(doc, compression); return ret; @@ -406,13 +430,16 @@ xmlTextWriterStartDocument(xmlTextWriterPtr writer, const char *version, xmlLinkPtr lk; xmlCharEncodingHandlerPtr encoder; - if ((writer == NULL) || (writer->out == NULL)) + if ((writer == NULL) || (writer->out == NULL)) { + xmlGenericError(xmlGenericErrorContext, + "xmlTextWriterStartDocument : invalid writer!\n"); return -1; + } lk = xmlListFront(writer->nodes); if ((lk != NULL) && (xmlLinkGetData(lk) != NULL)) { xmlGenericError(xmlGenericErrorContext, - "xmlTextWriterStartDocument : only one prolog allowed in an XML document!\n"); + "xmlTextWriterStartDocument : not allowed in this context!\n"); return -1; } @@ -517,8 +544,11 @@ xmlTextWriterEndDocument(xmlTextWriterPtr writer) xmlLinkPtr lk; xmlTextWriterStackEntry *p; - if (writer == NULL) + if (writer == NULL) { + xmlGenericError(xmlGenericErrorContext, + "xmlTextWriterEndDocument : invalid writer!\n"); return -1; + } sum = 0; while ((lk = xmlListFront(writer->nodes)) != NULL) { @@ -548,6 +578,14 @@ xmlTextWriterEndDocument(xmlTextWriterPtr writer) sum += count; break; case XML_TEXTWRITER_DTD: + 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: count = xmlTextWriterEndDTD(writer); if (count < 0) return -1; @@ -573,11 +611,6 @@ xmlTextWriterEndDocument(xmlTextWriterPtr writer) return sum; } - - - - - /** * xmlTextWriterStartComment: * @writer: the xmlTextWriterPtr @@ -594,8 +627,11 @@ xmlTextWriterStartComment(xmlTextWriterPtr writer) xmlLinkPtr lk; xmlTextWriterStackEntry *p; - if (writer == NULL) + if (writer == NULL) { + xmlGenericError(xmlGenericErrorContext, + "xmlTextWriterStartComment : invalid writer!\n"); return -1; + } sum = 0; lk = xmlListFront(writer->nodes); @@ -611,6 +647,13 @@ xmlTextWriterStartComment(xmlTextWriterPtr writer) 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_TEXT; break; default: @@ -633,10 +676,6 @@ xmlTextWriterStartComment(xmlTextWriterPtr writer) xmlListPushFront(writer->nodes, p); if (writer->indent) { - count = xmlOutputBufferWriteString(writer->out, "\n"); - if (count < 0) - return -1; - sum += count; count = xmlTextWriterWriteIndent(writer); if (count < 0) return -1; @@ -667,12 +706,18 @@ xmlTextWriterEndComment(xmlTextWriterPtr writer) xmlLinkPtr lk; xmlTextWriterStackEntry *p; - if (writer == NULL) + if (writer == NULL) { + xmlGenericError(xmlGenericErrorContext, + "xmlTextWriterEndComment : invalid writer!\n"); return -1; + } lk = xmlListFront(writer->nodes); - if (lk == 0) + if (lk == 0) { + xmlGenericError(xmlGenericErrorContext, + "xmlTextWriterEndComment : not allowed in this context!\n"); return -1; + } p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk); if (p == 0) @@ -743,8 +788,11 @@ xmlTextWriterWriteVFormatComment(xmlTextWriterPtr writer, int rc; xmlChar *buf; - if (writer == NULL) + if (writer == NULL) { + xmlGenericError(xmlGenericErrorContext, + "xmlTextWriterWriteVFormatComment : invalid writer!\n"); return -1; + } buf = xmlTextWriterVSprintf(format, argptr); if (buf == 0) @@ -1142,50 +1190,38 @@ xmlTextWriterWriteRawLen(xmlTextWriterPtr writer, const xmlChar * content, xmlLinkPtr lk; xmlTextWriterStackEntry *p; - if (writer == NULL) + if (writer == NULL) { + xmlGenericError(xmlGenericErrorContext, + "xmlTextWriterWriteRawLen : invalid writer!\n"); 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_NONE: - return -1; - case XML_TEXTWRITER_NAME: - count = xmlOutputBufferWriteString(writer->out, ">"); - if (count < 0) - return -1; - sum += count; - p->state = XML_TEXTWRITER_TEXT; - break; - case XML_TEXTWRITER_PI: - count = xmlOutputBufferWriteString(writer->out, " "); - if (count < 0) - return -1; - sum += count; - p->state = XML_TEXTWRITER_PI_TEXT; - break; - case XML_TEXTWRITER_DTD: - count = xmlOutputBufferWriteString(writer->out, " ["); - if (count < 0) - return -1; - sum += count; - p->state = XML_TEXTWRITER_DTD_TEXT; - break; - default: - break; } - count = xmlOutputBufferWrite(writer->out, len, (const char *) content); - if (count < 0) + if ((content == NULL) && (len > 0)) { + xmlGenericError(xmlGenericErrorContext, + "xmlTextWriterWriteRawLen : invalid content!\n"); return -1; - sum += count; + } + + sum = 0; + lk = xmlListFront(writer->nodes); + if (lk != 0) { + p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk); + count = xmlTextWriterHandleStateDependencies(writer, p); + if (count < 0) + return -1; + sum += count; + } + + if (writer->indent) + writer->doindent = 0; + + if (content != NULL) { + count = + xmlOutputBufferWrite(writer->out, len, (const char *) content); + if (count < 0) + return -1; + sum += count; + } return sum; } @@ -1272,82 +1308,45 @@ xmlTextWriterWriteVFormatString(xmlTextWriterPtr writer, int xmlTextWriterWriteString(xmlTextWriterPtr writer, const xmlChar * content) { - int count = 0; + int count; int sum; xmlLinkPtr lk; xmlTextWriterStackEntry *p; - xmlChar *buf = NULL; + xmlChar *buf; 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_NONE: + 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: + encode: + buf = xmlEncodeSpecialChars(NULL, content); + break; + case XML_TEXTWRITER_ATTRIBUTE: + buf = NULL; + xmlAttrSerializeTxtContent(writer->out->buffer, NULL, + NULL, content); + break; + } + } + } + + if (buf != NULL) { + count = xmlTextWriterWriteRaw(writer, buf); + if (count < 0) return -1; - case XML_TEXTWRITER_NAME: - count = xmlOutputBufferWriteString(writer->out, ">"); - if (count < 0) - return -1; - sum += count; - p->state = XML_TEXTWRITER_TEXT; - goto encode; - case XML_TEXTWRITER_PI: - count = xmlOutputBufferWriteString(writer->out, " "); - if (count < 0) - return -1; - sum += count; - p->state = XML_TEXTWRITER_PI_TEXT; - /* fallthrough */ - case XML_TEXTWRITER_PI_TEXT: - case XML_TEXTWRITER_TEXT: - encode: - buf = xmlEncodeSpecialChars(NULL, content); - if (buf == NULL) - count = -1; - break; - case XML_TEXTWRITER_ATTRIBUTE: - xmlAttrSerializeTxtContent(writer->out->buffer, NULL, - NULL, content); - break; - case XML_TEXTWRITER_DTD: - count = xmlOutputBufferWriteString(writer->out, " ["); - if (count < 0) - return -1; - sum += count; - p->state = XML_TEXTWRITER_DTD_TEXT; - /* fallthrough */ - case XML_TEXTWRITER_DTD_TEXT: - case XML_TEXTWRITER_DTD_ELEM: - case XML_TEXTWRITER_CDATA: - case XML_TEXTWRITER_COMMENT: - buf = xmlStrdup(content); - if (buf == NULL) - count = -1; - break; - default: - break; - } + sum += count; - if (writer->indent) - writer->doindent = 0; - - if (buf != 0) { - count = - xmlOutputBufferWriteString(writer->out, (const char *) buf); - xmlFree(buf); + if (buf != content) /* buf was allocated by us, so free it */ + xmlFree(buf); } - if (count < 0) - return -1; - sum += count; return sum; } @@ -1449,41 +1448,16 @@ xmlTextWriterWriteBase64(xmlTextWriterPtr writer, const char *data, 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_NONE: - return -1; - case XML_TEXTWRITER_NAME: - count = xmlOutputBufferWriteString(writer->out, ">"); + lk = xmlListFront(writer->nodes); + if (lk != 0) { + p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk); + if (p != 0) { + count = xmlTextWriterHandleStateDependencies(writer, p); if (count < 0) return -1; sum += count; - p->state = XML_TEXTWRITER_TEXT; - break; - case XML_TEXTWRITER_PI: - count = xmlOutputBufferWriteString(writer->out, " "); - if (count < 0) - return -1; - sum += count; - p->state = XML_TEXTWRITER_PI_TEXT; - break; - case XML_TEXTWRITER_DTD: - count = xmlOutputBufferWriteString(writer->out, " ["); - if (count < 0) - return -1; - sum += count; - p->state = XML_TEXTWRITER_DTD_TEXT; - break; - default: - break; + } } if (writer->indent) @@ -1565,41 +1539,16 @@ xmlTextWriterWriteBinHex(xmlTextWriterPtr writer, const char *data, 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_NONE: - return -1; - case XML_TEXTWRITER_NAME: - count = xmlOutputBufferWriteString(writer->out, ">"); + lk = xmlListFront(writer->nodes); + if (lk != 0) { + p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk); + if (p != 0) { + count = xmlTextWriterHandleStateDependencies(writer, p); if (count < 0) return -1; sum += count; - p->state = XML_TEXTWRITER_TEXT; - break; - case XML_TEXTWRITER_PI: - count = xmlOutputBufferWriteString(writer->out, " "); - if (count < 0) - return -1; - sum += count; - p->state = XML_TEXTWRITER_PI_TEXT; - break; - case XML_TEXTWRITER_DTD: - count = xmlOutputBufferWriteString(writer->out, " ["); - if (count < 0) - return -1; - sum += count; - p->state = XML_TEXTWRITER_DTD_TEXT; - break; - default: - break; + } } if (writer->indent) @@ -2741,7 +2690,20 @@ xmlTextWriterStartDTD(xmlTextWriterPtr writer, return -1; } - count = xmlOutputBufferWriteString(writer->out, " PUBLIC \""); + 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); if (count < 0) return -1; sum += count; @@ -2752,7 +2714,7 @@ xmlTextWriterStartDTD(xmlTextWriterPtr writer, return -1; sum += count; - count = xmlOutputBufferWriteString(writer->out, "\""); + count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar); if (count < 0) return -1; sum += count; @@ -2760,13 +2722,25 @@ xmlTextWriterStartDTD(xmlTextWriterPtr writer, if (sysid != 0) { if (pubid == 0) { - count = xmlOutputBufferWriteString(writer->out, " SYSTEM"); + 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; + } else if (writer->indent) { + count = xmlOutputBufferWriteString(writer->out, "\n "); if (count < 0) return -1; sum += count; } - count = xmlOutputBufferWriteString(writer->out, " \""); + count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar); if (count < 0) return -1; sum += count; @@ -2777,7 +2751,7 @@ xmlTextWriterStartDTD(xmlTextWriterPtr writer, return -1; sum += count; - count = xmlOutputBufferWriteString(writer->out, "\""); + count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar); if (count < 0) return -1; sum += count; @@ -2797,6 +2771,7 @@ xmlTextWriterStartDTD(xmlTextWriterPtr writer, int xmlTextWriterEndDTD(xmlTextWriterPtr writer) { + int loop; int count; int sum; xmlLinkPtr lk; @@ -2806,34 +2781,59 @@ xmlTextWriterEndDTD(xmlTextWriterPtr writer) 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_TEXT: - count = xmlOutputBufferWriteString(writer->out, "]"); - if (count < 0) - return -1; - sum += count; - /* fallthrough */ - case XML_TEXTWRITER_DTD: - case XML_TEXTWRITER_DTD_ELEM: - case XML_TEXTWRITER_DTD_ATTL: - count = xmlOutputBufferWriteString(writer->out, ">"); - if (count < 0) - return -1; - sum += count; + loop = 1; + while (loop) { + lk = xmlListFront(writer->nodes); + if (lk == NULL) break; - default: + 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, ">"); + + if (writer->indent) { + if (count < 0) + return -1; + sum += count; + count = xmlOutputBufferWriteString(writer->out, "\n"); + } + + 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) return -1; + sum += count; } - xmlListPopFront(writer->nodes); return sum; } @@ -2971,27 +2971,27 @@ xmlTextWriterStartDTDElement(xmlTextWriterPtr writer, const xmlChar * name) } p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk); - if (p == 0) - return -1; - - switch (p->state) { - case XML_TEXTWRITER_DTD: - count = xmlOutputBufferWriteString(writer->out, " ["); - if (count < 0) + 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; - sum += count; - p->state = XML_TEXTWRITER_DTD_TEXT; - /* fallthrough */ - case XML_TEXTWRITER_DTD_TEXT: - break; - case XML_TEXTWRITER_DTD_ELEM: - count = xmlTextWriterEndDTDElement(writer); - if (count < 0) - return -1; - sum += count; - break; - default: - return -1; + } } p = (xmlTextWriterStackEntry *) @@ -3013,6 +3013,13 @@ xmlTextWriterStartDTDElement(xmlTextWriterPtr writer, const xmlChar * name) xmlListPushFront(writer->nodes, p); + if (writer->indent) { + count = xmlTextWriterWriteIndent(writer); + if (count < 0) + return -1; + sum += count; + } + count = xmlOutputBufferWriteString(writer->out, "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; +} + /** * xmlTextWriterWriteFormatDTDElement: * @writer: the xmlTextWriterPtr @@ -3110,10 +3168,6 @@ xmlTextWriterWriteDTDElement(xmlTextWriterPtr writer, return -1; sum += count; - count = xmlTextWriterWriteString(writer, BAD_CAST " "); - if (count == -1) - return -1; - sum += count; count = xmlTextWriterWriteString(writer, content); if (count == -1) return -1; @@ -3154,29 +3208,27 @@ xmlTextWriterStartDTDAttlist(xmlTextWriterPtr writer, const xmlChar * name) } p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk); - if (p == 0) - return -1; - - switch (p->state) { - case XML_TEXTWRITER_DTD: - count = xmlOutputBufferWriteString(writer->out, " ["); - if (count < 0) + 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; - sum += count; - p->state = XML_TEXTWRITER_DTD_TEXT; - /* fallthrough */ - case XML_TEXTWRITER_DTD_TEXT: - break; - case XML_TEXTWRITER_DTD_ELEM: - case XML_TEXTWRITER_DTD_ATTL: - case XML_TEXTWRITER_DTD_ENTY: - count = xmlTextWriterEndDTD(writer); - if (count < 0) - return -1; - sum += count; - break; - default: - return -1; + } } p = (xmlTextWriterStackEntry *) @@ -3198,6 +3250,13 @@ xmlTextWriterStartDTDAttlist(xmlTextWriterPtr writer, const xmlChar * name) xmlListPushFront(writer->nodes, p); + if (writer->indent) { + count = xmlTextWriterWriteIndent(writer); + if (count < 0) + return -1; + sum += count; + } + count = xmlOutputBufferWriteString(writer->out, "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; +} + /** * xmlTextWriterWriteFormatDTDAttlist: * @writer: the xmlTextWriterPtr @@ -3295,10 +3405,6 @@ xmlTextWriterWriteDTDAttlist(xmlTextWriterPtr writer, return -1; sum += count; - count = xmlTextWriterWriteString(writer, BAD_CAST " "); - if (count == -1) - return -1; - sum += count; count = xmlTextWriterWriteString(writer, content); if (count == -1) return -1; @@ -3336,34 +3442,32 @@ xmlTextWriterStartDTDEntity(xmlTextWriterPtr writer, sum = 0; lk = xmlListFront(writer->nodes); - if (lk == 0) { - return -1; - } + if (lk != 0) { - p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk); - if (p == 0) - return -1; - - switch (p->state) { - case XML_TEXTWRITER_DTD: - count = xmlOutputBufferWriteString(writer->out, " ["); - if (count < 0) - return -1; - sum += count; - p->state = XML_TEXTWRITER_DTD_TEXT; - /* fallthrough */ - case XML_TEXTWRITER_DTD_TEXT: - break; - case XML_TEXTWRITER_DTD_ELEM: - case XML_TEXTWRITER_DTD_ATTL: - case XML_TEXTWRITER_DTD_ENTY: - count = xmlTextWriterEndDTD(writer); - if (count < 0) - return -1; - sum += count; - break; - default: - return -1; + 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; + } + } } p = (xmlTextWriterStackEntry *) @@ -3381,17 +3485,28 @@ xmlTextWriterStartDTDEntity(xmlTextWriterPtr writer, xmlFree(p); return -1; } - p->state = XML_TEXTWRITER_DTD_ENTY; + + if (pe != 0) + p->state = XML_TEXTWRITER_DTD_PENT; + else + p->state = XML_TEXTWRITER_DTD_ENTY; xmlListPushFront(writer->nodes, p); + if (writer->indent) { + count = xmlTextWriterWriteIndent(writer); + if (count < 0) + return -1; + sum += count; + } + count = xmlOutputBufferWriteString(writer->out, "out, " % "); + count = xmlOutputBufferWriteString(writer->out, "% "); if (count < 0) return -1; sum += count; @@ -3405,6 +3520,63 @@ xmlTextWriterStartDTDEntity(xmlTextWriterPtr writer, return sum; } +/** + * 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; + case XML_TEXTWRITER_DTD_ENTY: + case XML_TEXTWRITER_DTD_PENT: + enddtd: + 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; +} + /** * xmlTextWriterWriteFormatDTDInternalEntity: * @writer: the xmlTextWriterPtr @@ -3493,13 +3665,12 @@ xmlTextWriterWriteDTDEntity(xmlTextWriterPtr writer, const xmlChar * ndataid, const xmlChar * content) { - if (((content == NULL) && (pubid == NULL) && (sysid == NULL)) - || ((content != NULL) && ((pubid != NULL) || (sysid != NULL)))) + if ((content == NULL) && (pubid == NULL) && (sysid == NULL)) return -1; if ((pe != 0) && (ndataid != NULL)) return -1; - if (content != 0) + if ((pubid == NULL) && (sysid == NULL)) return xmlTextWriterWriteDTDInternalEntity(writer, pe, name, content); @@ -3536,22 +3707,10 @@ xmlTextWriterWriteDTDInternalEntity(xmlTextWriterPtr writer, return -1; sum += count; - count = xmlTextWriterWriteString(writer, BAD_CAST " "); - if (count == -1) - return -1; - sum += count; - count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar); - if (count < 0) - return -1; - sum += count; count = xmlTextWriterWriteString(writer, content); if (count == -1) return -1; sum += count; - count = xmlOutputBufferWrite(writer->out, 1, &writer->qchar); - if (count < 0) - return -1; - sum += count; count = xmlTextWriterEndDTDEntity(writer); if (count == -1) @@ -3570,7 +3729,7 @@ xmlTextWriterWriteDTDInternalEntity(xmlTextWriterPtr writer, * @sysid: the system identifier, which is the URI of the DTD * @ndataid: the xml notation name. * - * Write a DTD internal entity. + * Write a DTD external entity. The entity must have been started with xmlTextWriterStartDTDEntity * * Returns the bytes written (may be 0 because of buffering) or -1 in case of error */ @@ -3585,8 +3744,7 @@ xmlTextWriterWriteDTDExternalEntity(xmlTextWriterPtr writer, int count; int sum; - if ((name == NULL) || (*name == '\0') - || ((pubid == NULL) && (sysid == NULL))) + if (((pubid == NULL) && (sysid == NULL))) return -1; if ((pe != 0) && (ndataid != NULL)) return -1; @@ -3597,10 +3755,81 @@ xmlTextWriterWriteDTDExternalEntity(xmlTextWriterPtr writer, return -1; sum += count; + 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) { + xmlGenericError(xmlGenericErrorContext, + "xmlTextWriterWriteDTDExternalEntityContents: xmlTextWriterPtr invalid!\n"); + return -1; + } + + sum = 0; + lk = xmlListFront(writer->nodes); + if (lk == 0) { + xmlGenericError(xmlGenericErrorContext, + "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) { + xmlGenericError(xmlGenericErrorContext, + "xmlTextWriterWriteDTDExternalEntityContents: notation not allowed with parameter entities!\n"); + return -1; + } + break; + default: + xmlGenericError(xmlGenericErrorContext, + "xmlTextWriterWriteDTDExternalEntityContents: you must call xmlTextWriterStartDTDEntity before the call to this function!\n"); + return -1; + } + if (pubid != 0) { if (sysid == 0) { xmlGenericError(xmlGenericErrorContext, - "xmlTextWriterWriteDTDEntity : system identifier needed!\n"); + "xmlTextWriterWriteDTDExternalEntityContents: system identifier needed!\n"); return -1; } @@ -3670,11 +3899,6 @@ xmlTextWriterWriteDTDExternalEntity(xmlTextWriterPtr writer, sum += count; } - count = xmlTextWriterEndDTDEntity(writer); - if (count == -1) - return -1; - sum += count; - return sum; } @@ -3709,29 +3933,33 @@ xmlTextWriterWriteDTDNotation(xmlTextWriterPtr writer, } p = (xmlTextWriterStackEntry *) xmlLinkGetData(lk); - if (p == 0) - return -1; + 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: + return -1; + } + } - switch (p->state) { - case XML_TEXTWRITER_DTD: - count = xmlOutputBufferWriteString(writer->out, " ["); - if (count < 0) - return -1; - sum += count; - p->state = XML_TEXTWRITER_DTD_TEXT; - /* fallthrough */ - case XML_TEXTWRITER_DTD_TEXT: - break; - case XML_TEXTWRITER_DTD_ELEM: - case XML_TEXTWRITER_DTD_ATTL: - case XML_TEXTWRITER_DTD_ENTY: - count = xmlTextWriterEndDTD(writer); - if (count < 0) - return -1; - sum += count; - break; - default: + if (writer->indent) { + count = xmlTextWriterWriteIndent(writer); + if (count < 0) return -1; + sum += count; } count = xmlOutputBufferWriteString(writer->out, "state) { + case XML_TEXTWRITER_NAME: + 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; +} + #endif