Class element
Defined in File node.hpp
Inheritance Relationships
Base Type
public mxml::element_container
(Class element_container)
Class Documentation
-
class element : public mxml::element_container
the element class modelling a XML element
element is the most important mxml::node object. It encapsulates a XML element as found in the XML document. It has a qname, can have children, attributes and a namespace.
Public Functions
-
inline virtual constexpr node_type type() const override
node_type to be returned by each implementation of this node class
-
inline element()
default constructor
-
inline element(std::string_view qname, std::initializer_list<attribute> attributes = {})
constructor taking a qname and a list of attributes
-
inline element(std::string_view qname, std::initializer_list<element> il)
constructor taking a qname and a list of child elements
-
inline virtual std::string get_qname() const override
Return the qualified name.
-
inline virtual void set_qname(std::string qn) override
Set the qualified name to qn.
-
virtual std::string lang() const override
content of a xml:lang attribute of this element, or its nearest ancestor
-
std::string id() const
content of the xml:id attribute, or the attribute that was defined to be of type ID by the DOCTYPE.
-
inline attribute_set &attributes()
return the set of attributes for this element
-
inline const attribute_set &attributes() const
return the set of attributes for this element
-
virtual std::string namespace_for_prefix(std::string_view prefix) const override
return the URI of the namespace for prefix
-
virtual std::pair<std::string, bool> prefix_for_namespace(std::string_view uri) const override
return the prefix for the XML namespace with uri uri.
- Returns
The result is a pair of a std::string containing the actual prefix value and a boolean indicating if the namespace was found at all, needed since empty prefixes are allowed.
-
void move_to_name_space(std::string prefix, std::string uri, bool recursive, bool including_attributes)
move this element and optionally everyting beneath it to the specified namespace/prefix
- Parameters
prefix – The new prefix name
uri – The new namespace uri
recursive – Apply this to the child nodes as well
including_attributes – Move the attributes to this new namespace as well
-
std::string get_content() const
return the concatenation of the content of all enclosed mxml::text nodes
-
void set_content(std::string content)
replace all existing child text nodes with a new single text node containing content
-
std::string get_attribute(std::string_view qname) const
return the value of attribute name qname or the empty string if not found
-
void set_attribute(std::string_view qname, std::string_view value)
set the value of attribute named qname to the value value
-
virtual void set_text(std::string s)
The set_text method replaces any text node with the new text (call set_content)
-
void add_text(std::string s)
The add_text method checks if the last added child is a text node, and if so, it appends the string to this node’s value. Otherwise, it adds a new text node child with the new text.
-
void flatten_text()
To combine all adjacent child text nodes into one.
-
inline virtual void set_qname(std::string qn)
Set the qualified name to qn.
This is only meaningful in attributes and elements.
- Parameters
qn –
-
inline void set_qname(std::string prefix, std::string name)
set the qname with two parameters, if prefix is empty the qname will be simply name otherwise the name will be
prefix:name
- Parameters
prefix – The namespace prefix to use
name – The actual name to use
-
inline virtual constexpr node_type type() const override