scram::xml::Element
XML Element adaptor.
#include <xml.h>
Public Classes
| Name | |
|---|---|
| class | Range <br>The range for elements. |
Public Functions
| Name | |
|---|---|
| Element(const xmlElement * element) | |
| const char * | filename() const |
| int | line() const |
| std::string_view | name() const |
| bool | has_attribute(const char * name) const<br>Queries element attribute existence. |
| std::string_view | attribute(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_view | text() 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 |
| Range | children() const |
| auto | children(std::string_view name) const |
Public Functions Documentation
function Element
inline explicit Element(
const xmlElement * element
)Parameters:
- element The element in the XML document.
function filename
inline const char * filename() constReturn: The URI of the file containing the element.
Precondition: The document has been loaded from a file.
function line
inline int line() constReturn: The line number of the element.
function name
inline std::string_view name() constReturn: The name of the XML element.
Precondition: The element has a name.
function has_attribute
inline bool has_attribute(
const char * name
) constQueries 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
inline std::string_view attribute(
const char * name
) constRetrieves 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
template <typename T >
inline std::enable_if_t< std::is_arithmetic_v< T >, std::optional< T > > attribute(
const char * name
) constGeneric attribute value extraction following XML data types.
Parameters:
- name The name of the attribute.
Exceptions:
- ValidityError Casting is unsuccessful.
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
inline std::string_view text() constReturn: The XML element's text.
Precondition: The Element has text.
function text
template <typename T >
inline std::enable_if_t< std::is_arithmetic_v< T >, T > text() constGeneric text value extraction following XML data types.
Exceptions:
- ValidityError Casting is unsuccessful.
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
inline std::optional< Element > child(
std::string_view name =""
) constParameters:
- 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
inline Range children() constReturn: All the Element children.
function children
inline auto children(
std::string_view name
) constParameters:
- 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
