libxml2

Loading...
Searching...
No Matches
Functions
HTMLtree.h File Reference

HTML documents. More...

## Functions
xmlDoc * | htmlNewDoc (const xmlChar *URI, const xmlChar *ExternalID)
| Creates a new HTML document.
xmlDoc * | htmlNewDocNoDtD (const xmlChar *URI, const xmlChar *ExternalID)
| Creates a new HTML document without a DTD node if `URI` and `publicId` are NULL.
const xmlChar * | htmlGetMetaEncoding (xmlDoc *doc)
| Look up and encoding declaration in the meta tags.
int | htmlSetMetaEncoding (xmlDoc *doc, const xmlChar *encoding)
| Creates or updates a meta tag with an encoding declaration.
void | htmlDocDumpMemory (xmlDoc *cur, xmlChar **mem, int *size)
| Same as htmlDocDumpMemoryFormat with `format` set to 1 which is typically undesired.
void | htmlDocDumpMemoryFormat (xmlDoc *cur, xmlChar **mem, int *size, int format)
| Serialize an HTML node to a memory, also returning the size of the result.
int | htmlSaveFile (const char *filename, xmlDoc *cur)
| Serialize an HTML document to a file.
int | htmlSaveFileEnc (const char *filename, xmlDoc *cur, const char *encoding)
| Serialize an HTML document to a file.
int | htmlSaveFileFormat (const char *filename, xmlDoc *cur, const char *encoding, int format)
| Serialize an HTML document to a file using a given encoding.
int | htmlNodeDump (xmlBuffer *buf, xmlDoc *doc, xmlNode *cur)
| Serialize an HTML node to an xmlBuffer.
int | htmlDocDump (FILE *f, xmlDoc *cur)
| Serialize an HTML document to an open `FILE`.
void | htmlNodeDumpFile (FILE *out, xmlDoc *doc, xmlNode *cur)
| Same as htmlNodeDumpFileFormat with `format` set to 1 which is typically undesired.
int | htmlNodeDumpFileFormat (FILE *out, xmlDoc *doc, xmlNode *cur, const char *encoding, int format)
| Serialize an HTML node to an xmlBuffer.
void | htmlNodeDumpOutput (xmlOutputBuffer *buf, xmlDoc *doc, xmlNode *cur, const char *encoding)
| Same as htmlNodeDumpFormatOutput with `format` set to 1 which is typically undesired.
void | htmlNodeDumpFormatOutput (xmlOutputBuffer *buf, xmlDoc *doc, xmlNode *cur, const char *encoding, int format)
| Serialize an HTML node to an output buffer.
void | htmlDocContentDumpOutput (xmlOutputBuffer *buf, xmlDoc *cur, const char *encoding)
| Same as htmlDocContentDumpFormatOutput with `format` set to 1 which is typically undesired.
void | htmlDocContentDumpFormatOutput (xmlOutputBuffer *buf, xmlDoc *cur, const char *encoding, int format)
| Serialize an HTML document to an output buffer.
int | htmlIsBooleanAttr (const xmlChar *name)
| Determine if a given attribute is a boolean attribute.

## Detailed Description

HTML documents.

This modules implements functions to work with HTML documents, most of them related to serialization.

Copyright
  See Copyright for the status of this software.

Author
  Daniel Veillard

## Function Documentation

## ◆ htmlDocContentDumpFormatOutput()

void htmlDocContentDumpFormatOutput | ( | xmlOutputBuffer * | buf,
|  | xmlDoc * | cur,
|  | const char * | encoding,
|  | int | format
| ) |  |

Serialize an HTML document to an output buffer.

Parameters

  buf | the HTML buffer output
  cur | the document
  encoding | the encoding string (unused)
  format | should formatting newlines been added

## ◆ htmlDocContentDumpOutput()

void htmlDocContentDumpOutput | ( | xmlOutputBuffer * | buf,
|  | xmlDoc * | cur,
|  | const char * | encoding
| ) |  |

Same as htmlDocContentDumpFormatOutput with `format` set to 1 which is typically undesired.

Use of this function is DISCOURAGED in favor of htmlDocContentDumpFormatOutput.

Parameters

  buf | the HTML buffer output
  cur | the document
  encoding | the encoding string (unused)

## ◆ htmlDocDump()

int htmlDocDump | ( | FILE * | f,
|  | xmlDoc * | cur
| ) |  |

Serialize an HTML document to an open `FILE`.

Uses the encoding of the document. If the document has no encoding, ASCII with HTML 4.0 named character entities will be used. This is inefficient compared to UTF-8 and might be changed in a future version.

Enables "formatting" unconditionally which is typically undesired.

Use of this function is DISCOURAGED in favor of htmlNodeDumpFileFormat.

Parameters

  f | the FILE*
  cur | the document

Returns
  the number of bytes written or -1 in case of failure.

## ◆ htmlDocDumpMemory()

void htmlDocDumpMemory | ( | xmlDoc * | cur,
|  | xmlChar ** | mem,
|  | int * | size
| ) |  |

Same as htmlDocDumpMemoryFormat with `format` set to 1 which is typically undesired.

Also see the warnings there. Use of this function is DISCOURAGED in favor of htmlDocContentDumpFormatOutput.

Parameters

  cur | the document
  mem | OUT: the memory pointer
  size | OUT: the memory length

## ◆ htmlDocDumpMemoryFormat()

void htmlDocDumpMemoryFormat | ( | xmlDoc * | cur,
|  | xmlChar ** | mem,
|  | int * | size,
|  | int | format
| ) |  |

Serialize an HTML node to a memory, also returning the size of the result.

It's up to the caller to free the memory.

Uses the encoding of the document. If the document has no encoding, ASCII with HTML 4.0 named character entities will be used. This is inefficient compared to UTF-8 and might be changed in a future version.

Parameters

  cur | the document
  mem | OUT: the memory pointer
  size | OUT: the memory length
  format | should formatting newlines been added

## ◆ htmlGetMetaEncoding()

const xmlChar * htmlGetMetaEncoding | ( | xmlDoc * | doc | ) |

Look up and encoding declaration in the meta tags.

The returned string points into attribute content and can contain trailing garbage. It should be copied before modifying or freeing nodes.

Parameters

  doc | the document

Returns
  the encoding ot NULL if not found.

## ◆ htmlIsBooleanAttr()

int htmlIsBooleanAttr | ( | const xmlChar * | name | ) |

Determine if a given attribute is a boolean attribute.

This doesn't handle HTML5.

Deprecated:
  Internal function, don't use.

Parameters

  name | the name of the attribute to check

Returns
  false if the attribute is not boolean, true otherwise.

## ◆ htmlNewDoc()

xmlDoc * htmlNewDoc | ( | const xmlChar * | URI,
|  | const xmlChar * | publicId
| ) |  |

Creates a new HTML document.

Parameters

  URI | system ID (URI) of the DTD (optional)
  publicId | public ID of the DTD (optional)

Returns
  a new document

## ◆ htmlNewDocNoDtD()

xmlDoc * htmlNewDocNoDtD | ( | const xmlChar * | URI,
|  | const xmlChar * | publicId
| ) |  |

Creates a new HTML document without a DTD node if `URI` and `publicId` are NULL.

Parameters

  URI | system ID (URI) of the DTD (optional)
  publicId | public ID of the DTD (optional)

Returns
  a new document, do not initialize the DTD if not provided

## ◆ htmlNodeDump()

int htmlNodeDump | ( | xmlBuffer * | buf,
|  | xmlDoc * | doc,
|  | xmlNode * | cur
| ) |  |

Serialize an HTML node to an xmlBuffer.

Always uses UTF-8.

Parameters

  buf | the HTML buffer output
  doc | the document
  cur | the current node

Returns
  the number of bytes written or -1 in case of error

## ◆ htmlNodeDumpFile()

void htmlNodeDumpFile | ( | FILE * | out,
|  | xmlDoc * | doc,
|  | xmlNode * | cur
| ) |  |

Same as htmlNodeDumpFileFormat with `format` set to 1 which is typically undesired.

Use of this function is DISCOURAGED in favor of htmlNodeDumpFileFormat.

Parameters

  out | the FILE pointer
  doc | the document
  cur | the current node

## ◆ htmlNodeDumpFileFormat()

int htmlNodeDumpFileFormat | ( | FILE * | out,
|  | xmlDoc * | doc,
|  | xmlNode * | cur,
|  | const char * | encoding,
|  | int | format
| ) |  |

Serialize an HTML node to an xmlBuffer.

If encoding is NULL, ASCII with HTML 4.0 named character entities will be used. This is inefficient compared to UTF-8 and might be changed in a future version.

Parameters

  out | the FILE pointer
  doc | the document (unused)
  cur | the current node
  encoding | the document encoding (optional)
  format | should formatting newlines been added

Returns
  the number of bytes written or -1 in case of failure.

## ◆ htmlNodeDumpFormatOutput()

void htmlNodeDumpFormatOutput | ( | xmlOutputBuffer * | buf,
|  | xmlDoc * | doc,
|  | xmlNode * | cur,
|  | const char * | encoding,
|  | int | format
| ) |  |

Serialize an HTML node to an output buffer.

Parameters

  buf | the HTML buffer output
  doc | the document (unused)
  cur | the current node
  encoding | the encoding string (unused)
  format | should formatting newlines been added

## ◆ htmlNodeDumpOutput()

void htmlNodeDumpOutput | ( | xmlOutputBuffer * | buf,
|  | xmlDoc * | doc,
|  | xmlNode * | cur,
|  | const char * | encoding
| ) |  |

Same as htmlNodeDumpFormatOutput with `format` set to 1 which is typically undesired.

Use of this function is DISCOURAGED in favor of htmlNodeDumpFormatOutput.

Parameters

  buf | the HTML buffer output
  doc | the document (unused)
  cur | the current node
  encoding | the encoding string (unused)

## ◆ htmlSaveFile()

int htmlSaveFile | ( | const char * | filename,
|  | xmlDoc * | cur
| ) |  |

Serialize an HTML document to a file.

Same as htmlSaveFileFormat with `encoding` set to NULL and `format` set to 1 which is typically undesired.

Use of this function is DISCOURAGED in favor of htmlSaveFileFormat.

Parameters

  filename | the filename (or URL)
  cur | the document

Returns
  the number of bytes written or -1 in case of failure.

## ◆ htmlSaveFileEnc()

int htmlSaveFileEnc | ( | const char * | filename,
|  | xmlDoc * | cur,
|  | const char * | encoding
| ) |  |

Serialize an HTML document to a file.

Same as htmlSaveFileFormat with `format` set to 1 which is typically undesired. Also see the warnings there. Use of this function is DISCOURAGED in favor of htmlSaveFileFormat.

Parameters

  filename | the filename
  cur | the document
  encoding | the document encoding

Returns
  the number of bytes written or -1 in case of failure.

## ◆ htmlSaveFileFormat()

int htmlSaveFileFormat | ( | const char * | filename,
|  | xmlDoc * | cur,
|  | const char * | encoding,
|  | int | format
| ) |  |

Serialize an HTML document to a file using a given encoding.

If `filename` is `"-"`, stdout is used. This is potentially insecure and might be changed in a future version.

If encoding is NULL, ASCII with HTML 4.0 named character entities will be used. This is inefficient compared to UTF-8 and might be changed in a future version.

Sets or updates meta tags containing the character encoding.

Parameters

  filename | the filename
  cur | the document
  format | should formatting newlines been added
  encoding | the document encoding (optional)

Returns
  the number of bytes written or -1 in case of failure.

## ◆ htmlSetMetaEncoding()

int htmlSetMetaEncoding | ( | xmlDoc * | doc,
|  | const xmlChar * | encoding
| ) |  |

Creates or updates a meta tag with an encoding declaration.

NOTE: This will not change the document content encoding.

Parameters

  doc | the document
  encoding | the encoding string

Returns
  0 in case of success, 1 if no head element was found or arguments are invalid and -1 if memory allocation failed.