iDynTree::XMLElement class

Class representing an XML element.

This class represents an XML element encountered during parsing, i.e. the XML part between (and comprising) <tag> ... </tag>

Derived classes

class ForceTorqueSensorElement
class GeometryElement
class InertialElement
class JointElement
class LinkElement
class MaterialElement
class OriginElement
class RobotElement
class SensorElement
class VisualElement

Constructors, destructors, conversion operators

XMLElement(XMLParserState& parserState) explicit
Default constructor.
XMLElement(XMLParserState& parserState, const std::string& name) explicit
Constructs a named XML Element with no attributes.
XMLElement(XMLParserState& parserState, const std::string& name, const std::unordered_map<std::string, std::shared_ptr<iDynTree::XMLAttribute>>& attributes) explicit
Constructs a named XML Element with the specified attributes.
~XMLElement() virtual
Destructor.

Public functions

void setAttributeCallback(std::function<bool(const std::unordered_map<std::string, std::shared_ptr<iDynTree::XMLAttribute>>&)> callback)
Sets a callback that will be called when attributes will be parsed.
void setExitScopeCallback(std::function<void()> callback)
Sets a callback that will be called when the element has been finished parsing.
void setChildHasBeenParsedCallback(std::function<void(std::shared_ptr<XMLElement>)> callback)
Sets a callback that will be called when a child element has been finished parsing.
auto attributeCallback() const -> std::function<bool(const std::unordered_map<std::string, std::shared_ptr<iDynTree::XMLAttribute>>&)>
auto exitScopeCallback() const -> std::function<void()>
auto name() const -> std::string
auto children() const -> const std::vector<std::shared_ptr<XMLElement>>
auto attributes() const -> const std::unordered_map<std::string, std::shared_ptr<iDynTree::XMLAttribute>>
auto childElementForName(const std::string& name) -> std::shared_ptr<XMLElement> virtual
Factory method to create child element given the name.
void exitElementScope() virtual
void childHasBeenParsed(std::shared_ptr<XMLElement> parsedChild) virtual
auto setAttributes(const std::unordered_map<std::string, std::shared_ptr<iDynTree::XMLAttribute>>& attributes) -> bool virtual
void parsedCharacters(const std::string& characters) virtual
auto getParsedTextContent() const -> std::string
auto description() const -> std::string

Protected functions

auto getParserState() -> XMLParserState&

Function documentation

iDynTree::XMLElement::XMLElement(XMLParserState& parserState) explicit

Default constructor.

Parameters
parserState a reference to the parser state to propagate to the elements.

Constructs an unnamed XML Element with no attributes.

iDynTree::XMLElement::XMLElement(XMLParserState& parserState, const std::string& name) explicit

Constructs a named XML Element with no attributes.

Parameters
parserState a reference to the parser state to propagate to the elements.
name the name of the XML element.

iDynTree::XMLElement::XMLElement(XMLParserState& parserState, const std::string& name, const std::unordered_map<std::string, std::shared_ptr<iDynTree::XMLAttribute>>& attributes) explicit

Constructs a named XML Element with the specified attributes.

Parameters
parserState a reference to the parser state to propagate to the elements.
name the name of the XML element.
attributes the attributes of the XML element.

This is the designated initializer.

void iDynTree::XMLElement::setAttributeCallback(std::function<bool(const std::unordered_map<std::string, std::shared_ptr<iDynTree::XMLAttribute>>&)> callback)

Sets a callback that will be called when attributes will be parsed.

Parameters
callback the callback to be set

The function should have the following signature const std::unordered_map<std::string, std::shared_ptr<iDynTree::XMLAttribute>>& -> bool. The attributes parsed from the XML will be passed as argument to the function. In case of error, it should return false, true otherwise.

void iDynTree::XMLElement::setExitScopeCallback(std::function<void()> callback)

Sets a callback that will be called when the element has been finished parsing.

Parameters
callback the callback

The function should have the following signature void -> void.

void iDynTree::XMLElement::setChildHasBeenParsedCallback(std::function<void(std::shared_ptr<XMLElement>)> callback)

Sets a callback that will be called when a child element has been finished parsing.

Parameters
callback the callback

The callback should have the following signature std::shared_ptr<XMLElement> -> void, where the element passed is the child element that has been parsed.

std::shared_ptr<XMLElement> iDynTree::XMLElement::childElementForName(const std::string& name) virtual

Factory method to create child element given the name.

Parameters
name name of the element to create
Returns a new parser element for the corresponding tag