xml_structure_tree¶
Defined in header: <orcus/xml_structure_tree.hpp>
-
class xml_structure_tree¶
Tree representing the structure of elements in XML content. Recurring elements under the same parent are represented by a single element instance. This tree only includes elements; no attributes and content nodes appear in this tree.
Public Types
-
enum class callback_type : uint8_t¶
Location of a callback function.
Values:
-
enumerator unknown¶
Location not specified or unknown.
-
enumerator on_repeat_node¶
Callback function is called when a repeated element is encountered. The argument passed to the callback function contains the name of the repeated element and its type is
entity_name.
-
enumerator unknown¶
-
using callback_handler_type = std::function<void(std::any)>¶
Callback function type. It must take one argument. What value is assigned and what the type of a value is depends on the location of the callback. Refer to
callback_typefor details.
-
using range_handler_type = std::function<void(xml_table_range_t&&)>¶
-
typedef std::vector<entity_name> entity_names_type¶
Public Functions
-
xml_structure_tree() = delete¶
-
xml_structure_tree(const xml_structure_tree&) = delete¶
-
xml_structure_tree &operator=(const xml_structure_tree&) = delete¶
-
xml_structure_tree(xmlns_context &xmlns_cxt)¶
-
xml_structure_tree(xml_structure_tree &&other)¶
-
~xml_structure_tree()¶
-
void set_callback(callback_type type, callback_handler_type callback)¶
Assign a user-defined callback function in a specified point of execution during parsing.
- Parameters:
type – Location where the callback function will be called.
callback – Callback function.
-
void parse(std::string_view s)¶
-
void dump_compact(std::ostream &os) const¶
-
void process_ranges(range_handler_type rh) const¶
-
void swap(xml_structure_tree &other)¶
-
struct element¶
-
struct entity_name¶
Public Functions
-
entity_name()¶
-
entity_name(xmlns_id_t _ns, std::string_view _name)¶
-
bool operator<(const entity_name &r) const¶
-
bool operator==(const entity_name &r) const¶
-
struct hash¶
Public Functions
-
size_t operator()(const entity_name &val) const¶
-
size_t operator()(const entity_name &val) const¶
-
entity_name()¶
-
class walker¶
This class allows client to traverse the tree.
Public Functions
-
walker() = delete¶
-
~walker()¶
-
element root()¶
Set current position to the root element, and return the root element.
- Returns:
root element.
-
element descend(const entity_name &name)¶
Descend into a specified child element.
- Parameters:
name – name of a child element.
- Throws:
general_error – if no child elements exist for the specified name.
- Returns:
child element
-
element move_to(const std::string &path)¶
Move to the element specified by a path expression. The path expression may be generated by
xml_structure_tree::walker::get_path.- Parameters:
path – a simple XPath like expression
- Returns:
element pointed to by the path.
-
entity_names_type get_children()¶
Get a list of names of all child elements at the current element position. The list of names is in order of appearance.
- Returns:
list of child element names in order of appearance.
-
entity_names_type get_attributes()¶
Get a list of names of all attributes that belong to current element. The list of names is in order of appearance.
- Returns:
list of attribute names in order of appearance.
-
size_t get_xmlns_index(xmlns_id_t ns) const¶
Get a numerical, 0-based index of given XML namespace.
- Parameters:
ns – XML namespace ID.
- Returns:
numeric, 0-based index of XML namespace if found, or
xml_structure_tree::walker::index_not_foundif the namespace is not found in this structure.
-
std::string get_xmlns_short_name(xmlns_id_t ns) const¶
-
std::string to_string(const entity_name &name) const¶
Convert an entity name to its proper string representation.
- Parameters:
name – entity name to convert to string.
- Returns:
string representation of the entity name, including the namespace.
-
std::string get_path() const¶
Get a XPath like ID for the element inside of the XML tree.
-
walker() = delete¶
-
enum class callback_type : uint8_t¶