Skip to main content

Module tree

Module tree 

Source
Expand description

XML tree construction and manipulation (§17, §18, §85 Phase 1).

Complete tree construction/manipulation, namespaces, attributes, dictionaries, entity structures, document ownership, copying, linking, and freeing.

§UPSTREAM-PARITY

libxml2’s tree is an observable data structure. The pointer topology (parent, children, last, next, prev, doc, ns, properties, nsDef) is part of the compatibility contract and must be court-tested.

Key invariants (matching upstream):

  • node->doc points to the owning document (or NULL if not owned)
  • node->parent points to the parent element (or NULL for root)
  • node->children points to the first child
  • node->last points to the last child
  • node->next / node->prev form a doubly-linked list of siblings
  • node->properties points to the first attribute (for elements)
  • node->nsDef points to the first namespace declaration (for elements)
  • doc->children points to the root element
  • doc->doc points to itself (self-reference)

§Ownership model

Documents own all their nodes. When a document is freed, all nodes are freed. Nodes can be moved between documents via unlinking and re-adding.

§Phase 1 status

Complete — all tree operations are implemented. Future phases may add more edge-case handling for historical quirks.

Functions§

add_child
Add a child node to a parent.
add_sibling
Add a sibling node after another.
copy_doc
Copy a document (deep copy by default).
copy_node
Copy a node (shallow or deep).
doc_get_root_element
Get the root element of a document.
doc_set_root_element
Set the root element of a document.
free_doc
Free a document and all its contents.
free_node
Free a single node (without freeing children).
free_node_list
Free a linked list of nodes.
get_doc_entity
Get a document entity by name.
get_int_subset
Get the internal DTD subset of a document.
get_line_no
Get the line number of a node.
get_ns_list
Get a list of namespaces in scope for a node.
get_ns_prop
Get a namespaced attribute value.
get_parameter_entity
Get a parameter entity by name.
get_prop
Get an attribute value by name.
new_cdata_block
Create a new CDATA section node.
new_child
Create a new child element.
new_comment
Create a new comment node.
new_doc
Create a new XML document.
new_dtd
Create a new DTD node.
new_entity
Create a new entity.
new_node
Create a new XML node.
new_ns
Create a new namespace declaration.
new_pi
Create a new processing instruction node.
new_text
Create a new text node.
remove_prop
Remove a property from a node.
search_ns
Search for a namespace by prefix.
search_ns_by_href
Search for a namespace by href (URI).
set_ns
Set the namespace of a node.
set_ns_prop
Set a namespaced attribute.
set_prop
Set an attribute on a node.
unlink_node
Unlink a node from its parent/siblings.
xml_strlen
Get the length of a null-terminated xmlChar string.