document_tree

Defined in header: <orcus/dom_tree.hpp>

class document_tree

Ordinary DOM tree representing the content of an XML document.

Public Functions

document_tree(const document_tree&) = delete
document_tree &operator=(const document_tree&) = delete
document_tree(xmlns_repository &repo)
Parameters:

repo – Namespace repository used to mint namespace identifiers for the tree’s stored names. Must outlive the document_tree.

document_tree(document_tree &&other)
~document_tree()
void load(std::string_view strm)

Parse a given XML stream and build the content tree.

Parameters:

strm – XML stream.

dom::const_node root() const
dom::node set_root(entity_name name)

Replace the current root element with a fresh empty element of the given name. Any pre-existing root subtree is discarded. Other parts of the document (XML declaration, processing instructions, prolog/epilog comments, DOCTYPE) are preserved.

Parameters:

name – Name of the new root element.

Returns:

mutable handle to the newly created root element.

dom::const_node declaration() const
dom::node set_declaration()

Create the XML declaration if it does not already exist, and return a mutable handle to it. Use the returned handle’s set_attribute(name, value) overload to populate version, encoding, and standalone.

dom::const_node processing_instruction(std::string_view target) const
dom::node add_processing_instruction(std::string_view target)

Get or create a processing instruction with the given target, returning a mutable handle. If a processing instruction with the same target already exists, the existing one is returned unchanged.

void append_prolog_comment(std::string_view value)

Append a comment node before the root element (in the document prolog).

void append_epilog_comment(std::string_view value)

Append a comment node after the root element (in the document epilog).

dom::const_node declaration(std::string_view name) const
void swap(document_tree &other)

Swap the content with another dom_tree instance.

Parameters:

other – The dom_tree instance to swap the content with.

const sax::doctype_declaration *get_doctype() const
std::string dump(std::size_t indent) const

Dump the XML document tree to string.

Parameters:

indent – Number of whitespace characters to use for one indent level. Note that specifying the indent value of 0 will generate output without line breaks.

Returns:

A string representation of the XML document tree.

void dump_compact(std::ostream &os) const