libdom
Loading...
Searching...
No Matches
document.h File Reference
#include <inttypes.h>
#include <stddef.h>
#include <dom/core/node.h>
#include <dom/core/attr.h>
#include <dom/core/cdatasection.h>
#include <dom/core/comment.h>
#include <dom/core/document.h>
#include <dom/core/document_type.h>
#include <dom/core/doc_fragment.h>
#include <dom/core/element.h>
#include <dom/core/entity_ref.h>
#include <dom/core/pi.h>
#include <dom/core/text.h>
#include <dom/core/implementation.h>
#include "core/string.h"
#include "core/node.h"
#include "core/nodelist.h"
#include "utils/hashtable.h"
#include "utils/list.h"
#include "events/document_event.h"

Go to the source code of this file.

Classes

struct  dom_document
 

Macros

#define DOM_DOCUMENT_VTABLE
 
#define DOM_NODE_VTABLE_DOCUMENT
 
#define DOM_DOCUMENT_PROTECT_VTABLE
 
#define _dom_document_get_id_name(d)
 

Functions

dom_exception _dom_document_create (dom_events_default_action_fetcher daf, void *daf_ctx, dom_document **doc)
 
dom_exception _dom_document_initialise (dom_document *doc, dom_events_default_action_fetcher daf, void *daf_ctx)
 
bool _dom_document_finalise (dom_document *doc)
 
dom_exception _dom_document_get_doctype (dom_document *doc, dom_document_type **result)
 
dom_exception _dom_document_get_implementation (dom_document *doc, dom_implementation **result)
 
dom_exception _dom_document_get_document_element (dom_document *doc, dom_element **result)
 
dom_exception _dom_document_create_element (dom_document *doc, dom_string *tag_name, dom_element **result)
 
dom_exception _dom_document_create_document_fragment (dom_document *doc, dom_document_fragment **result)
 
dom_exception _dom_document_create_text_node (dom_document *doc, dom_string *data, dom_text **result)
 
dom_exception _dom_document_create_comment (dom_document *doc, dom_string *data, dom_comment **result)
 
dom_exception _dom_document_create_cdata_section (dom_document *doc, dom_string *data, dom_cdata_section **result)
 
dom_exception _dom_document_create_processing_instruction (dom_document *doc, dom_string *target, dom_string *data, dom_processing_instruction **result)
 
dom_exception _dom_document_create_attribute (dom_document *doc, dom_string *name, dom_attr **result)
 
dom_exception _dom_document_create_entity_reference (dom_document *doc, dom_string *name, dom_entity_reference **result)
 
dom_exception _dom_document_get_elements_by_tag_name (dom_document *doc, dom_string *tagname, dom_nodelist **result)
 
dom_exception _dom_document_import_node (dom_document *doc, dom_node *node, bool deep, dom_node **result)
 
dom_exception _dom_document_create_element_ns (dom_document *doc, dom_string *namespace, dom_string *qname, dom_element **result)
 
dom_exception _dom_document_create_attribute_ns (dom_document *doc, dom_string *namespace, dom_string *qname, dom_attr **result)
 
dom_exception _dom_document_get_elements_by_tag_name_ns (dom_document *doc, dom_string *namespace, dom_string *localname, dom_nodelist **result)
 
dom_exception _dom_document_get_element_by_id (dom_document *doc, dom_string *id, dom_element **result)
 
dom_exception _dom_document_get_input_encoding (dom_document *doc, dom_string **result)
 
dom_exception _dom_document_get_xml_encoding (dom_document *doc, dom_string **result)
 
dom_exception _dom_document_get_xml_standalone (dom_document *doc, bool *result)
 
dom_exception _dom_document_set_xml_standalone (dom_document *doc, bool standalone)
 
dom_exception _dom_document_get_xml_version (dom_document *doc, dom_string **result)
 
dom_exception _dom_document_set_xml_version (dom_document *doc, dom_string *version)
 
dom_exception _dom_document_get_strict_error_checking (dom_document *doc, bool *result)
 
dom_exception _dom_document_set_strict_error_checking (dom_document *doc, bool strict)
 
dom_exception _dom_document_get_uri (dom_document *doc, dom_string **result)
 
dom_exception _dom_document_set_uri (dom_document *doc, dom_string *uri)
 
dom_exception _dom_document_adopt_node (dom_document *doc, dom_node *node, dom_node **result)
 
dom_exception _dom_document_get_dom_config (dom_document *doc, struct dom_configuration **result)
 
dom_exception _dom_document_normalize (dom_document *doc)
 
dom_exception _dom_document_rename_node (dom_document *doc, dom_node *node, dom_string *namespace, dom_string *qname, dom_node **result)
 
dom_exception _dom_document_get_quirks_mode (dom_document *doc, dom_document_quirks_mode *result)
 
dom_exception _dom_document_set_quirks_mode (dom_document *doc, dom_document_quirks_mode result)
 
dom_exception _dom_document_get_text_content (dom_node_internal *node, dom_string **result)
 
dom_exception _dom_document_set_text_content (dom_node_internal *node, dom_string *content)
 
void _dom_document_destroy (dom_node_internal *node)
 
dom_exception _dom_document_copy (dom_node_internal *old, dom_node_internal **copy)
 
void _dom_document_try_destroy (dom_document *doc)
 
dom_exception _dom_document_get_nodelist (dom_document *doc, nodelist_type type, dom_node_internal *root, dom_string *tagname, dom_string *namespace, dom_string *localname, dom_nodelist **list)
 
void _dom_document_remove_nodelist (dom_document *doc, dom_nodelist *list)
 
dom_exception _dom_find_element_by_id (dom_node_internal *root, dom_string *id, dom_element **result)
 
void _dom_document_set_id_name (dom_document *doc, dom_string *name)
 

Macro Definition Documentation

◆ _dom_document_get_id_name

#define _dom_document_get_id_name ( d)
Value:
(d->id_name)

◆ DOM_DOCUMENT_PROTECT_VTABLE

#define DOM_DOCUMENT_PROTECT_VTABLE
Value:
void _dom_document_destroy(dom_node_internal *node)
Definition document.c:1238
dom_exception _dom_document_copy(dom_node_internal *old, dom_node_internal **copy)
Definition document.c:1248

◆ DOM_DOCUMENT_VTABLE

#define DOM_DOCUMENT_VTABLE

◆ DOM_NODE_VTABLE_DOCUMENT

#define DOM_NODE_VTABLE_DOCUMENT

Function Documentation

◆ _dom_document_adopt_node()

dom_exception _dom_document_adopt_node ( dom_document * doc,
dom_node * node,
dom_node ** result )

Attempt to adopt a node from another document into this document

Parameters
docThe document to adopt into
nodeThe node to adopt
resultPointer to location to receive adopted node
Returns
DOM_NO_ERR on success, DOM_NO_MODIFICATION_ALLOWED_ERR if node is readonly, DOM_NOT_SUPPORTED_ERR if node is of type Document or DocumentType

The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.

Note
: The spec said adoptNode may be light weight than the importNode because the former need no Node creation. But in our implementation this can't be ensured. Both adoptNode and importNode create new nodes using the importing/adopting document's resource manager. So, generally, the adoptNode and importNode call the same function dom_document_dup_node.

◆ _dom_document_copy()

dom_exception _dom_document_copy ( dom_node_internal * old,
dom_node_internal ** copy )

◆ _dom_document_create()

dom_exception _dom_document_create ( dom_events_default_action_fetcher daf,
void * daf_ctx,
dom_document ** doc )

Create a Document

Parameters
docPointer to location to receive created document
dafThe default action fetcher
Returns
DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion.

The returned document will already be referenced.

◆ _dom_document_create_attribute()

dom_exception _dom_document_create_attribute ( dom_document * doc,
dom_string * name,
dom_attr ** result )

Create an attribute

Parameters
docThe document owning the attribute
nameThe name of the attribute
resultPointer to location to receive result
Returns
DOM_NO_ERR on success, DOM_INVALID_CHARACTER_ERR if name is invalid.

The constructed attribute will always be classified as 'specified'.

The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.

◆ _dom_document_create_attribute_ns()

dom_exception _dom_document_create_attribute_ns ( dom_document * doc,
dom_string * namespace,
dom_string * qname,
dom_attr ** result )

Create an attribute from the qualified name and namespace URI

Parameters
docThe document owning the attribute
namespaceThe namespace URI to use
qnameThe qualified name of the attribute
resultPointer to location to receive result
Returns
DOM_NO_ERR on success, DOM_INVALID_CHARACTER_ERR if qname is invalid, DOM_NAMESPACE_ERR if qname is malformed, or it has a prefix and namespace is NULL, or qname has a prefix "xml" and namespace is not "http://www.w3.org/XML/1998/namespace", or qname has a prefix "xmlns" and namespace is not "http://www.w3.org/2000/xmlns", or namespace is "http://www.w3.org/2000/xmlns" and qname is not (or is not prefixed by) "xmlns", DOM_NOT_SUPPORTED_ERR if doc does not support the "XML" feature.

The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.

◆ _dom_document_create_cdata_section()

dom_exception _dom_document_create_cdata_section ( dom_document * doc,
dom_string * data,
dom_cdata_section ** result )

Create a CDATA section

Parameters
docThe document owning the section
dataThe data for the section contents
resultPointer to location to receive result
Returns
DOM_NO_ERR on success, DOM_NOT_SUPPORTED_ERR if this is an HTML document.

The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.

◆ _dom_document_create_comment()

dom_exception _dom_document_create_comment ( dom_document * doc,
dom_string * data,
dom_comment ** result )

Create a comment node

Parameters
docThe document owning the node
dataThe data for the node
resultPointer to location to receive result
Returns
DOM_NO_ERR.

The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.

◆ _dom_document_create_document_fragment()

dom_exception _dom_document_create_document_fragment ( dom_document * doc,
dom_document_fragment ** result )

Create a document fragment

Parameters
docThe document owning the fragment
resultPointer to location to receive result
Returns
DOM_NO_ERR.

The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.

◆ _dom_document_create_element()

dom_exception _dom_document_create_element ( dom_document * doc,
dom_string * tag_name,
dom_element ** result )

Create an element

Parameters
docThe document owning the element
tag_nameThe name of the element
resultPointer to location to receive result
Returns
DOM_NO_ERR on success, DOM_INVALID_CHARACTER_ERR if tag_name is invalid.

doc and tag_name will have their reference counts increased.

The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.

◆ _dom_document_create_element_ns()

dom_exception _dom_document_create_element_ns ( dom_document * doc,
dom_string * namespace,
dom_string * qname,
dom_element ** result )

Create an element from the qualified name and namespace URI

Parameters
docThe document owning the element
namespaceThe namespace URI to use, or NULL for none
qnameThe qualified name of the element
resultPointer to location to receive result
Returns
DOM_NO_ERR on success, DOM_INVALID_CHARACTER_ERR if qname is invalid, DOM_NAMESPACE_ERR if qname is malformed, or it has a prefix and namespace is NULL, or qname has a prefix "xml" and namespace is not "http://www.w3.org/XML/1998/namespace", or qname has a prefix "xmlns" and namespace is not "http://www.w3.org/2000/xmlns", or namespace is "http://www.w3.org/2000/xmlns" and qname is not (or is not prefixed by) "xmlns", DOM_NOT_SUPPORTED_ERR if doc does not support the "XML" feature.

The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.

◆ _dom_document_create_entity_reference()

dom_exception _dom_document_create_entity_reference ( dom_document * doc,
dom_string * name,
dom_entity_reference ** result )

Create an entity reference

Parameters
docThe document owning the reference
nameThe name of the entity to reference
resultPointer to location to receive result
Returns
DOM_NO_ERR on success, DOM_INVALID_CHARACTER_ERR if name is invalid, DOM_NOT_SUPPORTED_ERR if this is an HTML document.

The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.

◆ _dom_document_create_processing_instruction()

dom_exception _dom_document_create_processing_instruction ( dom_document * doc,
dom_string * target,
dom_string * data,
dom_processing_instruction ** result )

Create a processing instruction

Parameters
docThe document owning the instruction
targetThe instruction target
dataThe data for the node
resultPointer to location to receive result
Returns
DOM_NO_ERR on success, DOM_INVALID_CHARACTER_ERR if target is invalid, DOM_NOT_SUPPORTED_ERR if this is an HTML document.

The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.

◆ _dom_document_create_text_node()

dom_exception _dom_document_create_text_node ( dom_document * doc,
dom_string * data,
dom_text ** result )

Create a text node

Parameters
docThe document owning the node
dataThe data for the node
resultPointer to location to receive result
Returns
DOM_NO_ERR.

The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.

◆ _dom_document_destroy()

void _dom_document_destroy ( dom_node_internal * node)

◆ _dom_document_finalise()

bool _dom_document_finalise ( dom_document * doc)

◆ _dom_document_get_doctype()

dom_exception _dom_document_get_doctype ( dom_document * doc,
dom_document_type ** result )

Retrieve the doctype of a document

Parameters
docThe document to retrieve the doctype from
resultPointer to location to receive result
Returns
DOM_NO_ERR.

The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.

◆ _dom_document_get_document_element()

dom_exception _dom_document_get_document_element ( dom_document * doc,
dom_element ** result )

Retrieve the document element of a document

Parameters
docThe document to retrieve the document element from
resultPointer to location to receive result
Returns
DOM_NO_ERR.

The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.

◆ _dom_document_get_dom_config()

dom_exception _dom_document_get_dom_config ( dom_document * doc,
struct dom_configuration ** result )

Retrieve the DOM configuration associated with a document

Parameters
docThe document to query
resultPointer to location to receive result
Returns
DOM_NOT_SUPPORTED_ERR, we don't support this API now.

The returned object will have its reference count increased. It is the responsibility of the caller to unref the object once it has finished with it.

◆ _dom_document_get_element_by_id()

dom_exception _dom_document_get_element_by_id ( dom_document * doc,
dom_string * id,
dom_element ** result )

Retrieve the element that matches the specified ID

Parameters
docThe document to search in
idThe ID to search for
resultPointer to location to receive result
Returns
DOM_NO_ERR on success, appropriate dom_exception on failure.

The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.

◆ _dom_document_get_elements_by_tag_name()

dom_exception _dom_document_get_elements_by_tag_name ( dom_document * doc,
dom_string * tagname,
dom_nodelist ** result )

Retrieve a list of all elements with a given tag name

Parameters
docThe document to search in
tagnameThe tag name to search for ("*" for all)
resultPointer to location to receive result
Returns
DOM_NO_ERR.

The returned list will have its reference count increased. It is the responsibility of the caller to unref the list once it has finished with it.

◆ _dom_document_get_elements_by_tag_name_ns()

dom_exception _dom_document_get_elements_by_tag_name_ns ( dom_document * doc,
dom_string * namespace,
dom_string * localname,
dom_nodelist ** result )

Retrieve a list of all elements with a given local name and namespace URI

Parameters
docThe document to search in
namespaceThe namespace URI
localnameThe local name
resultPointer to location to receive result
Returns
DOM_NO_ERR on success, appropriate dom_exception on failure.

The returned list will have its reference count increased. It is the responsibility of the caller to unref the list once it has finished with it.

◆ _dom_document_get_implementation()

dom_exception _dom_document_get_implementation ( dom_document * doc,
dom_implementation ** result )

Retrieve the DOM implementation that handles this document

Parameters
docThe document to retrieve the implementation from
resultPointer to location to receive result
Returns
DOM_NO_ERR.

The returned implementation will have its reference count increased. It is the responsibility of the caller to unref the implementation once it has finished with it.

◆ _dom_document_get_input_encoding()

dom_exception _dom_document_get_input_encoding ( dom_document * doc,
dom_string ** result )

Retrieve the input encoding of the document

Parameters
docThe document to query
resultPointer to location to receive result
Returns
DOM_NOT_SUPPORTED_ERR, we don't support this API now.

The returned string will have its reference count increased. It is the responsibility of the caller to unref the string once it has finished with it.

◆ _dom_document_get_nodelist()

dom_exception _dom_document_get_nodelist ( dom_document * doc,
nodelist_type type,
dom_node_internal * root,
dom_string * tagname,
dom_string * namespace,
dom_string * localname,
dom_nodelist ** list )

Get a nodelist, creating one if necessary

Parameters
docThe document to get a nodelist for
typeThe type of the NodeList
rootRoot node of subtree that list applies to
tagnameName of nodes in list (or NULL)
namespaceNamespace part of nodes in list (or NULL)
localnameLocal part of nodes in list (or NULL)
listPointer to location to receive list
Returns
DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion

The returned list will have its reference count increased. It is the responsibility of the caller to unref the list once it has finished with it.

◆ _dom_document_get_quirks_mode()

dom_exception _dom_document_get_quirks_mode ( dom_document * doc,
dom_document_quirks_mode * result )

◆ _dom_document_get_strict_error_checking()

dom_exception _dom_document_get_strict_error_checking ( dom_document * doc,
bool * result )

Retrieve the error checking mode of the document

Parameters
docThe document to query
resultPointer to location to receive result
Returns
DOM_NOT_SUPPORTED_ERR, we don't support this API now.

◆ _dom_document_get_text_content()

dom_exception _dom_document_get_text_content ( dom_node_internal * node,
dom_string ** result )

◆ _dom_document_get_uri()

dom_exception _dom_document_get_uri ( dom_document * doc,
dom_string ** result )

Retrieve the URI of the document

Parameters
docThe document to query
resultPointer to location to receive result
Returns
DOM_NO_ERR.

The returned string will have its reference count increased. It is the responsibility of the caller to unref the string once it has finished with it.

◆ _dom_document_get_xml_encoding()

dom_exception _dom_document_get_xml_encoding ( dom_document * doc,
dom_string ** result )

Retrieve the XML encoding of the document

Parameters
docThe document to query
resultPointer to location to receive result
Returns
DOM_NOT_SUPPORTED_ERR, we don't support this API now.

The returned string will have its reference count increased. It is the responsibility of the caller to unref the string once it has finished with it.

◆ _dom_document_get_xml_standalone()

dom_exception _dom_document_get_xml_standalone ( dom_document * doc,
bool * result )

Retrieve the standalone status of the document

Parameters
docThe document to query
resultPointer to location to receive result
Returns
DOM_NOT_SUPPORTED_ERR, we don't support this API now.

◆ _dom_document_get_xml_version()

dom_exception _dom_document_get_xml_version ( dom_document * doc,
dom_string ** result )

Retrieve the XML version of the document

Parameters
docThe document to query
resultPointer to location to receive result
Returns
DOM_NO_ERR

The returned string will have its reference count increased. It is the responsibility of the caller to unref the string once it has finished with it.

We don't support this API now, so the return value is always DOM_NOT_SUPPORTED_ERR.

◆ _dom_document_import_node()

dom_exception _dom_document_import_node ( dom_document * doc,
dom_node * node,
bool deep,
dom_node ** result )

Import a node from another document into this one

Parameters
docThe document to import into
nodeThe node to import
deepWhether to copy the node's subtree
resultPointer to location to receive imported node in this document.
Returns
DOM_NO_ERR on success, DOM_INVALID_CHARACTER_ERR if any of the names are invalid, DOM_NOT_SUPPORTED_ERR if the type of node is unsupported

The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.

◆ _dom_document_initialise()

dom_exception _dom_document_initialise ( dom_document * doc,
dom_events_default_action_fetcher daf,
void * daf_ctx )

◆ _dom_document_normalize()

dom_exception _dom_document_normalize ( dom_document * doc)

Normalize a document

Parameters
docThe document to normalize
Returns
DOM_NOT_SUPPORTED_ERR, we don't support this API now.

◆ _dom_document_remove_nodelist()

void _dom_document_remove_nodelist ( dom_document * doc,
dom_nodelist * list )

Remove a nodelist from a document

Parameters
docThe document to remove the list from
listThe list to remove

◆ _dom_document_rename_node()

dom_exception _dom_document_rename_node ( dom_document * doc,
dom_node * node,
dom_string * namespace,
dom_string * qname,
dom_node ** result )

Rename a node in a document

Parameters
docThe document containing the node
nodeThe node to rename
namespaceThe new namespace for the node
qnameThe new qualified name for the node
resultPointer to location to receive renamed node
Returns
DOM_NO_ERR on success, DOM_INVALID_CHARACTER_ERR if tag_name is invalid, DOM_WRONG_DOCUMENT_ERR if node was created in a different document DOM_NAMESPACE_ERR if qname is malformed, or it has a prefix and namespace is NULL, or qname has a prefix "xml" and namespace is not "http://www.w3.org/XML/1998/namespace", or qname has a prefix "xmlns" and namespace is not "http://www.w3.org/2000/xmlns", or namespace is "http://www.w3.org/2000/xmlns" and qname is not (or is not prefixed by) "xmlns", DOM_NOT_SUPPORTED_ERR if doc does not support the "XML" feature.

The returned node will have its reference count increased. It is the responsibility of the caller to unref the node once it has finished with it.

We don't support this API now, so the return value is always DOM_NOT_SUPPORTED_ERR.

◆ _dom_document_set_id_name()

void _dom_document_set_id_name ( dom_document * doc,
dom_string * name )

Set the ID attribute name of this document

Parameters
docThe document object
nameThe ID name of the elements in this document

◆ _dom_document_set_quirks_mode()

dom_exception _dom_document_set_quirks_mode ( dom_document * doc,
dom_document_quirks_mode result )

◆ _dom_document_set_strict_error_checking()

dom_exception _dom_document_set_strict_error_checking ( dom_document * doc,
bool strict )

Set the error checking mode of the document

Parameters
docThe document to query
strictWhether to use strict error checking
Returns
DOM_NOT_SUPPORTED_ERR, we don't support this API now.

◆ _dom_document_set_text_content()

dom_exception _dom_document_set_text_content ( dom_node_internal * node,
dom_string * content )

◆ _dom_document_set_uri()

dom_exception _dom_document_set_uri ( dom_document * doc,
dom_string * uri )

Set the URI of the document

Parameters
docThe document to query
uriThe URI to use
Returns
DOM_NO_ERR.

The returned string will have its reference count increased. It is the responsibility of the caller to unref the string once it has finished with it.

◆ _dom_document_set_xml_standalone()

dom_exception _dom_document_set_xml_standalone ( dom_document * doc,
bool standalone )

Set the standalone status of the document

Parameters
docThe document to query
standaloneStandalone status to use
Returns
DOM_NO_ERR on success, DOM_NOT_SUPPORTED_ERR if the document does not support the "XML" feature.

We don't support this API now, so the return value is always DOM_NOT_SUPPORTED_ERR.

◆ _dom_document_set_xml_version()

dom_exception _dom_document_set_xml_version ( dom_document * doc,
dom_string * version )

Set the XML version of the document

Parameters
docThe document to query
versionXML version to use
Returns
DOM_NO_ERR on success, DOM_NOT_SUPPORTED_ERR if the document does not support the "XML" feature.

We don't support this API now, so the return value is always DOM_NOT_SUPPORTED_ERR.

◆ _dom_document_try_destroy()

void _dom_document_try_destroy ( dom_document * doc)

Try to destroy the document.

Parameters
docThe instance of Document

Delete the document if:

  1. The refcnt reach zero
  2. The pending list is empty

else, do nothing.

◆ _dom_find_element_by_id()

dom_exception _dom_find_element_by_id ( dom_node_internal * root,
dom_string * id,
dom_element ** result )

Find element with certain ID in the subtree rooted at root

Parameters
rootThe root element from where we start
idThe ID of the target element
resultThe result element
Returns
DOM_NO_ERR on success, appropriate dom_exception on failure.