MUSX Document Model
Loading...
Searching...
No Matches
musx::xml::IXmlElement Class Referenceabstract

Interface for an XML element. More...

#include <XmlInterface.h>

+ Inheritance diagram for musx::xml::IXmlElement:

Public Member Functions

virtual std::string getTagName () const =0
 Gets the tag name of the element.
 
virtual std::string getText () const =0
 Gets the text content of the element.
 
std::string getTextTrimmed () const
 Gets the text content of the element with whitespace trimmed.
 
template<typename T >
getTextAs (T defaultValue={}) const
 Gets the text content of the element, converted to the specified type.
 
virtual std::shared_ptr< IXmlAttributegetFirstAttribute () const =0
 Gets the first attribute.
 
virtual std::shared_ptr< IXmlAttributefindAttribute (const std::string &name) const =0
 Finds the first attribute.
 
virtual XmlElementPtr getFirstChildElement (const std::string &tagName={}) const =0
 Finds the first child element.
 
virtual XmlElementPtr getNextSibling (const std::string &tagName={}) const =0
 Gets the next sibling element.
 
virtual XmlElementPtr getPreviousSibling (const std::string &tagName={}) const =0
 Gets the previous sibling element.
 
virtual XmlElementPtr getParent () const =0
 Gets the parent element.
 

Detailed Description

Interface for an XML element.

Member Function Documentation

◆ findAttribute()

virtual std::shared_ptr< IXmlAttribute > musx::xml::IXmlElement::findAttribute ( const std::string &  name) const
pure virtual

Finds the first attribute.

Parameters
nameThe name of the attribute to find.
Returns
A shared pointer to the attribute, or nullptr if not found.

Implemented in musx::xml::pugi::Element, musx::xml::rapidxml::Element, and musx::xml::tinyxml2::Element.

◆ getFirstAttribute()

virtual std::shared_ptr< IXmlAttribute > musx::xml::IXmlElement::getFirstAttribute ( ) const
pure virtual

Gets the first attribute.

Returns
A shared pointer to the attribute, or nullptr if not found.

Implemented in musx::xml::pugi::Element, musx::xml::rapidxml::Element, and musx::xml::tinyxml2::Element.

◆ getFirstChildElement()

virtual XmlElementPtr musx::xml::IXmlElement::getFirstChildElement ( const std::string &  tagName = {}) const
pure virtual

Finds the first child element.

Parameters
tagName[optional] The tag name of the child elements to find. If omitted or empty, finds the first child with any name.
Returns
A shared pointer to the child element, or nullptr if not found.

Implemented in musx::xml::pugi::Element, musx::xml::rapidxml::Element, and musx::xml::tinyxml2::Element.

◆ getNextSibling()

virtual XmlElementPtr musx::xml::IXmlElement::getNextSibling ( const std::string &  tagName = {}) const
pure virtual

Gets the next sibling element.

Parameters
tagName[optional] The tag name of the sibling elements to find. If omitted or empty, finds the next sibling with any name.
Returns
A shared pointer to the next sibling element, or nullptr if not found.

Implemented in musx::xml::pugi::Element, musx::xml::rapidxml::Element, and musx::xml::tinyxml2::Element.

◆ getParent()

virtual XmlElementPtr musx::xml::IXmlElement::getParent ( ) const
pure virtual

Gets the parent element.

Returns
A shared pointer to the parent element, or nullptr if not applicable.

Implemented in musx::xml::pugi::Element, musx::xml::rapidxml::Element, and musx::xml::tinyxml2::Element.

◆ getPreviousSibling()

virtual XmlElementPtr musx::xml::IXmlElement::getPreviousSibling ( const std::string &  tagName = {}) const
pure virtual

Gets the previous sibling element.

Parameters
tagName[optional] The tag name of the sibling elements to find. If omitted or empty, finds the previous sibling with any name.
Returns
A shared pointer to the previous sibling element, or nullptr if not found.

Implemented in musx::xml::pugi::Element, musx::xml::rapidxml::Element, and musx::xml::tinyxml2::Element.

◆ getTagName()

virtual std::string musx::xml::IXmlElement::getTagName ( ) const
pure virtual

Gets the tag name of the element.

Returns
The tag name of the element.

Implemented in musx::xml::pugi::Element, musx::xml::rapidxml::Element, and musx::xml::tinyxml2::Element.

◆ getText()

virtual std::string musx::xml::IXmlElement::getText ( ) const
pure virtual

Gets the text content of the element.

Returns
The text content of the element.

Implemented in musx::xml::pugi::Element, musx::xml::rapidxml::Element, and musx::xml::tinyxml2::Element.

◆ getTextAs()

template<typename T >
T musx::xml::IXmlElement::getTextAs ( defaultValue = {}) const
inline

Gets the text content of the element, converted to the specified type.

Template Parameters
TThe type to which the text content should be converted.
Parameters
defaultValueThe value to return if the text of the element is empty.
Returns
The text content converted to the specified type.
Exceptions
std::invalid_argumentif the conversion fails.