zen::Xml: zen::XmlElement Class Reference

| zen::Xml Simple C++ XML Processing

- Main Page
- Namespaces
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Functions Variables Pages
Public Member Functions | List of all members
zen::XmlElement Class Reference

An XML element. More...

`#include <dom.h>`

## Public Member Functions
template<class String >
String | getNameAs () const
| Retrieve the name of this XML element. More...
template<class T >
bool | getValue (T &value) const
| Get the value of this element as a user type. More...
template<class T >
void | setValue (const T &value)
| Set the value of this element. More...
template<class String , class T >
bool | getAttribute (const String &name, T &value) const
| Retrieve an attribute by name. More...
template<class String , class T >
void | setAttribute (const String &name, const T &value)
| Create or update an XML attribute. More...
template<class String >
void | removeAttribute (const String &name)
| Remove the attribute with the given name. More...
template<class String >
XmlElement & | addChild (const String &name)
| Create a new child element and return a reference to it. More...
template<class String >
const XmlElement * | getChild (const String &name) const
| Retrieve a child element with the given name. More...
template<class String >
XmlElement * | getChild (const String &name)
template<class String >
std::pair< ChildIterConst2, ChildIterConst2 > | getChildren (const String &name) const
| Access all child elements with the given name via STL iterators. More...
template<class String >
std::pair< ChildIter2, ChildIter2 > | getChildren (const String &name)
std::pair< ChildIterConst, ChildIterConst > | getChildren () const
| Access all child elements sequentially via STL iterators. More...
std::pair< ChildIter, ChildIter > | getChildren ()
XmlElement * | parent ()
| Get parent XML element, may be nullptr for root element.
const XmlElement * | parent () const
| Get parent XML element, may be nullptr for root element.

## Detailed Description

An XML element.

## Member Function Documentation

template<class String >

XmlElement& zen::XmlElement::addChild | ( | const String & | name | ) |

Create a new child element and return a reference to it.

Template Parameters

  String | Arbitrary string-like type: e.g. std::string, wchar_t*, char[], wchar_t, wxString, MyStringClass, ...

Parameters

  name | The name of the child element to be created.

template<class String , class T >

bool zen::XmlElement::getAttribute | ( | const String & | name,
|  | T & | value
| ) |  | const

Retrieve an attribute by name.

Template Parameters

  String | Arbitrary string-like type: e.g. std::string, wchar_t*, char[], wchar_t, wxString, MyStringClass, ...
  T | String-convertible user data type: e.g. any string class, all built-in arithmetic numbers

Parameters

  name | The name of the attribute to retrieve.
  value | The value of the attribute converted to T.

Returns
  "true" if value was retrieved successfully.

template<class String >

const XmlElement* zen::XmlElement::getChild | ( | const String & | name | ) | const

Retrieve a child element with the given name.

Template Parameters

  String | Arbitrary string-like type: e.g. std::string, wchar_t*, char[], wchar_t, wxString, MyStringClass, ...

Parameters

  name | The name of the child element to be retrieved.

Returns
  A pointer to the child element or nullptr if none was found.

template<class String >

XmlElement* zen::XmlElement::getChild | ( | const String & | name | ) |

See also
  getChild

template<class String >

std::pair<ChildIterConst2, ChildIterConst2> zen::XmlElement::getChildren | ( | const String & | name | ) | const

Access all child elements with the given name via STL iterators.

auto iterPair = elem.getChildren("Item");
std::for_each(iterPair.first, iterPair.second,
[](const XmlElement& child) { ... });

Parameters

  name | The name of the child elements to be retrieved.

Returns
  A pair of STL begin/end iterators to access the child elements sequentially.

template<class String >

std::pair<ChildIter2, ChildIter2> zen::XmlElement::getChildren | ( | const String & | name | ) |

See also
  getChildren

std::pair<ChildIterConst, ChildIterConst> zen::XmlElement::getChildren | ( |  | ) | const

Access all child elements sequentially via STL iterators.

auto iterPair = elem.getChildren();
std::for_each(iterPair.first, iterPair.second,
[](const XmlElement& child) { ... });

Returns
  A pair of STL begin/end iterators to access all child elements sequentially.

std::pair<ChildIter, ChildIter> zen::XmlElement::getChildren | ( |  | ) |

See also
  getChildren

template<class String >

String zen::XmlElement::getNameAs | ( |  | ) | const

Retrieve the name of this XML element.

Template Parameters

  String | Arbitrary string class: e.g. std::string, std::wstring, wxString, MyStringClass, ...

Returns
  Name of the XML element.

template<class T >

bool zen::XmlElement::getValue | ( | T & | value | ) | const

Get the value of this element as a user type.

Template Parameters

  T | Arbitrary user data type: e.g. any string class, all built-in arithmetic numbers, STL container, ...

Returns
  "true" if Xml element was successfully converted to value, cannot fail for string-like types

template<class String >

void zen::XmlElement::removeAttribute | ( | const String & | name | ) |

Remove the attribute with the given name.

Template Parameters

  String | Arbitrary string-like type: e.g. std::string, wchar_t*, char[], wchar_t, wxString, MyStringClass, ...

template<class String , class T >

void zen::XmlElement::setAttribute | ( | const String & | name,
|  | const T & | value
| ) |  |

Create or update an XML attribute.

Template Parameters

  String | Arbitrary string-like type: e.g. std::string, wchar_t*, char[], wchar_t, wxString, MyStringClass, ...
  T | String-convertible user data type: e.g. any string-like type, all built-in arithmetic numbers

Parameters

  name | The name of the attribute to create or update.
  value | The value to set.

template<class T >

void zen::XmlElement::setValue | ( | const T & | value | ) |

Set the value of this element.

Template Parameters

  T | Arbitrary user data type: e.g. any string-like type, all built-in arithmetic numbers, STL container, ...