libxml2

Loading...
Searching...
No Matches
Typedefs | Enumerations | Functions
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
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.
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.
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.
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.
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.

Copyright
  See Copyright for the status of this software.

Author
  Daniel Veillard

## Enumeration Type Documentation

## ◆ xmlSaveOption

enum 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

  ctxt | a 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

  ctxt | a document saving context
  doc | a 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

  ctxt | a 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

  ctxt | a 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

  ctxt | a document saving context
  escape | the 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

  ctxt | a document saving context
  escape | the 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

  ctxt | save context
  indent | indent 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

  buffer | a buffer
  encoding | the encoding name to use or NULL
  options | a 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

  fd | a file descriptor number
  encoding | the encoding name to use (optional)
  options | a 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

  filename | a file name or an URL
  encoding | the encoding name to use or NULL
  options | a 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

  iowrite | an I/O write function
  ioclose | an I/O close function
  ioctx | an I/O handler
  encoding | the encoding name to use or NULL
  options | a 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

  ctxt | a document saving context
  cur | the 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

  v | new 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

  v | new 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

  v | new value

Returns
  the old value