node

Defined in header: <orcus/dom_tree.hpp>

class node : public orcus::dom::const_node

Mutable handle into an XML DOM tree. Inherits all read-only accessors from const_node and adds methods to build and edit a tree in place.

Note

A node is a lightweight value-type handle into storage owned by the enclosing document_tree. Do not use a node after its document_tree has been destroyed.

Public Functions

node()
node(const node &other)
node(node &&other)
~node()
node &operator=(const node &other)
node append_element(entity_name name)

Append a new child element to this element.

Parameters:

name – Name of the new child element.

Throws:

std::invalid_argument – if this node is not an element.

Returns:

mutable handle to the newly created child element.

void append_content(std::string_view value)

Append a text content node to this element.

Parameters:

value – Text content.

Throws:

std::invalid_argument – if this node is not an element.

void append_comment(std::string_view value)

Append a comment node to this element.

Parameters:

value – Comment text (without the surrounding <!-- -->).

Throws:

std::invalid_argument – if this node is not an element.

void set_attribute(entity_name name, std::string_view value)

Set or update a namespaced attribute on this element. If an attribute with the same namespace-name pair already exists, its value is replaced.

Parameters:
  • name – Attribute name (with namespace).

  • value – Attribute value.

Throws:

std::invalid_argument – if this node is not an element.

void set_attribute(std::string_view name, std::string_view value)

Set or update an attribute that has no explicit namespace. Use this for the XML declaration, processing instructions, and element attributes without a namespace prefix. If an attribute with the same name already exists, its value is replaced.

Parameters:
  • name – Attribute name.

  • value – Attribute value.

Throws:

std::invalid_argument – if this node is unset.

void set_name(entity_name name)

Change the name of this element.

Throws:

std::invalid_argument – if this node is not an element.

void declare_namespace(std::string_view alias, xmlns_id_t ns)

Declare a namespace prefix on this element. An empty alias declares a default namespace.

Parameters:
  • alias – Namespace prefix (or empty for the default namespace).

  • ns – Namespace identifier to bind to the prefix.

Throws:

std::invalid_argument – if this node is not an element.