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->docpoints to the owning document (or NULL if not owned)node->parentpoints to the parent element (or NULL for root)node->childrenpoints to the first childnode->lastpoints to the last childnode->next/node->prevform a doubly-linked list of siblingsnode->propertiespoints to the first attribute (for elements)node->nsDefpoints to the first namespace declaration (for elements)doc->childrenpoints to the root elementdoc->docpoints 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.