Skip to content

scram::xml::Element

XML Element adaptor.

#include <xml.h>

Public Classes

Name
classRange <br>The range for elements.

Public Functions

Name
Element(const xmlElement * element)
const char *filename() const
intline() const
std::string_viewname() const
boolhas_attribute(const char * name) const<br>Queries element attribute existence.
std::string_viewattribute(const char * name) const<br>Retrieves the XML element's attribute values.
template <typename T > <br>std::enable_if_t< std::is_arithmetic_v< T >, std::optional< T > >attribute(const char * name) const<br>Generic attribute value extraction following XML data types.
std::string_viewtext() const
template <typename T > <br>std::enable_if_t< std::is_arithmetic_v< T >, T >text() const<br>Generic text value extraction following XML data types.
std::optional< Element >child(std::string_view name ="") const
Rangechildren() const
autochildren(std::string_view name) const

Public Functions Documentation

function Element

cpp
inline explicit Element(
    const xmlElement * element
)

Parameters:

  • element The element in the XML document.

function filename

cpp
inline const char * filename() const

Return: The URI of the file containing the element.

Precondition: The document has been loaded from a file.

function line

cpp
inline int line() const

Return: The line number of the element.

function name

cpp
inline std::string_view name() const

Return: The name of the XML element.

Precondition: The element has a name.

function has_attribute

cpp
inline bool has_attribute(
    const char * name
) const

Queries element attribute existence.

Parameters:

  • name The non-empty attribute name.

Return: true if the element has an attribute with the given name.

Note: This is an inefficient way to work with optional attributes. Use the attribute(name) member function directly for optionals.

function attribute

cpp
inline std::string_view attribute(
    const char * name
) const

Retrieves the XML element's attribute values.

Parameters:

  • name The name of the requested attribute.

Return: The attribute value or empty string if no attribute (optional attribute).

Precondition:

  • XML attributes never contain empty strings.
  • XML attribute values are simple texts w/o DTD processing.

function attribute

cpp
template <typename T >
inline std::enable_if_t< std::is_arithmetic_v< T >, std::optional< T > > attribute(
    const char * name
) const

Generic attribute value extraction following XML data types.

Parameters:

  • name The name of the attribute.

Exceptions:

Template Parameters:

  • T The attribute value type (numeric).

Return: The value of type T interpreted from attribute value. None if the attribute doesn't exists (optional).

function text

cpp
inline std::string_view text() const

Return: The XML element's text.

Precondition: The Element has text.

function text

cpp
template <typename T >
inline std::enable_if_t< std::is_arithmetic_v< T >, T > text() const

Generic text value extraction following XML data types.

Exceptions:

Template Parameters:

  • T The attribute value type (numeric).

Return: The value of type T interpreted from attribute value.

Precondition: The text is not empty.

function child

cpp
inline std::optional< Element > child(
    std::string_view name =""
) const

Parameters:

  • name The name of the child element. Empty string to request any first child element.

Return: The first child element (with the given name).

function children

cpp
inline Range children() const

Return: All the Element children.

function children

cpp
inline auto children(
    std::string_view name
) const

Parameters:

  • name The name to filter children elements.

Return: The range of Element children with the given name.

Precondition: The name must live at least as long as the returned range lives.


Updated on 2025-11-11 at 16:51:08 +0000