libxml2
Loading...
Searching...
No Matches
xmlsave.h File Reference

XML/HTML serializer. More...

Typedefs

typedef struct _xmlSaveCtxt xmlSaveCtxt
 XML and HTML serializer.

Enumerations

enum  xmlSaveOption
 This is the set of XML save options that can be passed down to the xmlSaveToFd and similar calls. More...

Functions

xmlSaveCtxtxmlSaveToFd (int fd, const char *encoding, int options)
 Create a document saving context serializing to a file descriptor with the encoding and the options given.
xmlSaveCtxtxmlSaveToFilename (const char *filename, const char *encoding, int options)
 Create a document saving context serializing to a filename with the encoding and the options given.
xmlSaveCtxtxmlSaveToBuffer (xmlBuffer *buffer, const char *encoding, int options)
 Create a document saving context serializing to a buffer with the encoding and the options given.
xmlSaveCtxtxmlSaveToIO (xmlOutputWriteCallback iowrite, xmlOutputCloseCallback ioclose, void *ioctx, const char *encoding, int options)
 Create a document saving context serializing to a file descriptor with the encoding and the options given.
long xmlSaveDoc (xmlSaveCtxt *ctxt, xmlDoc *doc)
 Serialize a document.
long xmlSaveTree (xmlSaveCtxt *ctxt, xmlNode *node)
 Serialize a subtree starting.
int xmlSaveFlush (xmlSaveCtxt *ctxt)
 Flush a document saving context, i.e.
int xmlSaveClose (xmlSaveCtxt *ctxt)
 Close a document saving context, i.e.
xmlParserErrors xmlSaveFinish (xmlSaveCtxt *ctxt)
 Close a document saving context, i.e.
int xmlSaveSetIndentString (xmlSaveCtxt *ctxt, const char *indent)
 Sets the indent string.
int xmlSaveSetEscape (xmlSaveCtxt *ctxt, xmlCharEncodingOutputFunc escape)
 Set a custom escaping function to be used for text in element content.
int xmlSaveSetAttrEscape (xmlSaveCtxt *ctxt, xmlCharEncodingOutputFunc escape)
 Has no effect.
int xmlThrDefIndentTreeOutput (int v)
 Set per-thread default value.
const char * xmlThrDefTreeIndentString (const char *v)
 Set per-thread default value.
int xmlThrDefSaveNoEmptyTags (int v)
 Set per-thread default value.

Detailed Description

XML/HTML serializer.

API to save documents or subtrees of documents.

Author
Daniel Veillard

Enumeration Type Documentation

◆ xmlSaveOption

This is the set of XML save options that can be passed down to the xmlSaveToFd and similar calls.

Enumerator
XML_SAVE_FORMAT 

Format output.

This adds newlines and enables indenting by default.

XML_SAVE_NO_DECL 

Don't emit an XML declaration.

XML_SAVE_NO_EMPTY 

Don't emit empty tags.

XML_SAVE_NO_XHTML 

Don't serialize as XHTML.

XML_SAVE_XHTML 

Always serialize as XHTML.

XML_SAVE_AS_XML 

Serialize HTML documents as XML.

XML_SAVE_AS_HTML 

Serialize XML documents as HTML.

XML_SAVE_WSNONSIG 

Format with non-significant whitespace.

TODO: What does this mean?

XML_SAVE_EMPTY 

Always emit empty tags.

This is the default unless the deprecated thread-local setting xmlSaveNoEmptyTags is set to 1.

Since
2.14
XML_SAVE_NO_INDENT 

Don't indent output when formatting.

Since
2.14
XML_SAVE_INDENT 

Always indent output when formatting.

This is the default unless the deprecated thread-local setting xmlIndentTreeOutput is set to 0.

Since
2.14

Function Documentation

◆ xmlSaveClose()

int xmlSaveClose ( xmlSaveCtxt * ctxt)

Close a document saving context, i.e.

make sure that all buffered input has been processed and free the context struct.

Parameters
ctxta document saving context
Returns
the number of bytes written or -1 in case of error.

◆ xmlSaveDoc()

long xmlSaveDoc ( xmlSaveCtxt * ctxt,
xmlDoc * doc )

Serialize a document.

If the save context has no encoding, uses the document's encoding. If the document has no encoding, uses ASCII without an encoding declaration.

Parameters
ctxta document saving context
doca document
Returns
0 on success or -1 in case of error.

◆ xmlSaveFinish()

xmlParserErrors xmlSaveFinish ( xmlSaveCtxt * ctxt)

Close a document saving context, i.e.

make sure that all buffered input has been processed and free the context struct.

Since
2.13.0
Parameters
ctxta document saving context
Returns
an xmlParserErrors code.

◆ xmlSaveFlush()

int xmlSaveFlush ( xmlSaveCtxt * ctxt)

Flush a document saving context, i.e.

make sure that all buffered input has been processed.

Parameters
ctxta document saving context
Returns
the number of bytes written or -1 in case of error.

◆ xmlSaveSetAttrEscape()

int xmlSaveSetAttrEscape ( xmlSaveCtxt * ctxt,
xmlCharEncodingOutputFunc escape )

Has no effect.

Deprecated
Don't use.
Parameters
ctxta document saving context
escapethe escaping function
Returns
0 if successful or -1 in case of error.

◆ xmlSaveSetEscape()

int xmlSaveSetEscape ( xmlSaveCtxt * ctxt,
xmlCharEncodingOutputFunc escape )

Set a custom escaping function to be used for text in element content.

Deprecated
Don't use.
Parameters
ctxta document saving context
escapethe escaping function
Returns
0 if successful or -1 in case of error.

◆ xmlSaveSetIndentString()

int xmlSaveSetIndentString ( xmlSaveCtxt * ctxt,
const char * indent )

Sets the indent string.

Since
2.14.0
Parameters
ctxtsave context
indentindent string
Returns
0 on success, -1 if the string is NULL, empty or too long.

◆ xmlSaveToBuffer()

xmlSaveCtxt * xmlSaveToBuffer ( xmlBuffer * buffer,
const char * encoding,
int options )

Create a document saving context serializing to a buffer with the encoding and the options given.

If encoding is NULL, xmlSaveDoc uses the document's encoding and xmlSaveTree uses UTF-8.

This function doesn't allow to distinguish unsupported encoding errors from failed memory allocations.

Parameters
buffera buffer
encodingthe encoding name to use or NULL
optionsa set of xmlSaveOptions
Returns
a new serialization context or NULL in case of error.

◆ xmlSaveToFd()

xmlSaveCtxt * xmlSaveToFd ( int fd,
const char * encoding,
int options )

Create a document saving context serializing to a file descriptor with the encoding and the options given.

If encoding is NULL, xmlSaveDoc uses the document's encoding and xmlSaveTree uses UTF-8.

This function doesn't allow to distinguish unsupported encoding errors from failed memory allocations.

Parameters
fda file descriptor number
encodingthe encoding name to use (optional)
optionsa set of xmlSaveOptions
Returns
a new serialization context or NULL in case of error.

◆ xmlSaveToFilename()

xmlSaveCtxt * xmlSaveToFilename ( const char * filename,
const char * encoding,
int options )

Create a document saving context serializing to a filename with the encoding and the options given.

If encoding is NULL, xmlSaveDoc uses the document's encoding and xmlSaveTree uses UTF-8.

This function doesn't allow to distinguish unsupported encoding errors from failed memory allocations.

Parameters
filenamea file name or an URL
encodingthe encoding name to use or NULL
optionsa set of xmlSaveOptions
Returns
a new serialization context or NULL in case of error.

◆ xmlSaveToIO()

xmlSaveCtxt * xmlSaveToIO ( xmlOutputWriteCallback iowrite,
xmlOutputCloseCallback ioclose,
void * ioctx,
const char * encoding,
int options )

Create a document saving context serializing to a file descriptor with the encoding and the options given.

If encoding is NULL, xmlSaveDoc uses the document's encoding and xmlSaveTree uses UTF-8.

This function doesn't allow to distinguish unsupported encoding errors from failed memory allocations.

Parameters
iowritean I/O write function
ioclosean I/O close function
ioctxan I/O handler
encodingthe encoding name to use or NULL
optionsa set of xmlSaveOptions
Returns
a new serialization context or NULL in case of error.

◆ xmlSaveTree()

long xmlSaveTree ( xmlSaveCtxt * ctxt,
xmlNode * cur )

Serialize a subtree starting.

If the save context has no encoding, uses UTF-8.

Parameters
ctxta document saving context
curthe root of the subtree to save
Returns
0 on success or -1 in case of error.

◆ xmlThrDefIndentTreeOutput()

int xmlThrDefIndentTreeOutput ( int v)

Set per-thread default value.

Deprecated
Indenting is enabled by default. Use the xmlsave.h API and xmlSaveOption XML_SAVE_NO_INDENT to disable indenting.
Parameters
vnew value
Returns
the old value

◆ xmlThrDefSaveNoEmptyTags()

int xmlThrDefSaveNoEmptyTags ( int v)

Set per-thread default value.

Deprecated
Use the xmlsave.h API and xmlSaveOption XML_SAVE_NO_EMPTY.
Parameters
vnew value
Returns
the old value

◆ xmlThrDefTreeIndentString()

const char * xmlThrDefTreeIndentString ( const char * v)

Set per-thread default value.

Deprecated
Use the xmlsave.h API and xmlSaveSetIndentString.
Parameters
vnew value
Returns
the old value