A class representing a node in an XML-tree.
More...
The XMLObject class allows to read and store an XML-tree. The root element can be created using
Each object has the following members:
- xmlns : refers to the XML namespace
- className : refers to the class it belong to
- elementName : refers to the name used in the XML
- prefix : refers to the namespace prefix in the XML
- textContent : textual content of XML element without children
- attributes : a list of attributes containing the namespace, prefix, attribute name, and attribute value
- children : a list of child elements
Derived classes with dedicated members for attributes and children are automatically generated by schematic++ according to respective XML schema definition(s).
Each XMLObject can be converted to a string using stringify() and printed to an output stream using operator<<(std::ostream& os, const XMLObject* obj) and operator<<(std::ostream& os, const XMLObject& obj) .
Definition at line 129 of file XMLObject.h.
#include <XMLObject.h>
|
| virtual | ~XMLObject () |
| template<typename T, typename Self> |
| auto * | is (this Self &&self) |
| | Returns a pointer of type T of the object, const-qualified to match the receiver.
|
| template<typename T, typename Self> |
| auto * | get (this Self &&self) |
| | Attempt to cast the current instance to the specified type T.
|
| template<typename T, typename Self> |
| auto | find (this Self &&self) |
| | Find all descendants of type T.
|
| std::string | stringify () const |
| | Convert the XMLObject and its children to a string representation.
|
| std::string | format (std::string indentation="\t", unsigned int depth=0) const |
| | Creates formatted string representing the XMLObject including its children.
|
| template<typename T, typename Self> |
| auto & | getRequiredChild (this Self &&self) |
| | Get a required child of type T.
|
| template<typename T, typename Self> |
| auto | getOptionalChild (this Self &&self) |
| | Get an optional child of type T.
|
| template<typename T, typename Self> |
| auto | getChildren (this Self &&self) |
| | Get all children of type T.
|
| template<typename Self> |
| auto & | getRequiredChildByName (this Self &&self, const ElementName &name) |
| | Get a required child with the specified element name.
|
| template<typename Self> |
| auto | getOptionalChildByName (this Self &&self, const ElementName &name) |
| | Get the optional child with the specified element name.
|
| template<typename Self> |
| auto | getChildrenByName (this Self &&self, const ElementName &name) |
| | Get all children with the specified element name.
|
| template<typename Self> |
| auto & | getRequiredAttributeByName (this Self &&self, const AttributeName &name) |
| | Get a required attribute with the specified attribute name.
|
| template<typename Self> |
| auto | getOptionalAttributeByName (this Self &&self, const AttributeName &name) |
| | Get an optional attribute with the specified attribute name.
|
◆ ~XMLObject()
| virtual XML::XMLObject::~XMLObject |
( |
| ) |
|
|
inlinevirtual |
◆ XMLObject()
| XML::XMLObject::XMLObject |
( |
const Namespace & | xmlns, |
|
|
const ClassName & | className, |
|
|
const xercesc::DOMElement * | element, |
|
|
const Attributes & | defaultAttributes ) |
|
protected |
◆ createFromFile()
| XMLObject * XML::XMLObject::createFromFile |
( |
const std::string & | filename | ) |
|
|
static |
- Parameters
-
| filename | The path to the XML file. |
- Returns
- A pointer to the created XMLObject.
- Exceptions
-
| std::runtime_error | if loading the file or parsing the XML fails. |
Definition at line 81 of file XMLObject.cpp.
◆ createFromStream()
| XMLObject * XML::XMLObject::createFromStream |
( |
std::istream & | xmlStream | ) |
|
|
static |
- Parameters
-
| xmlStream | The input stream containing the XML data. |
- Returns
- A pointer to the created XMLObject.
- Exceptions
-
| std::runtime_error | if parsing the XML fails. |
Definition at line 47 of file XMLObject.cpp.
◆ createFromString()
| XMLObject * XML::XMLObject::createFromString |
( |
const std::string & | xmlString | ) |
|
|
static |
- Parameters
-
| xmlString | The string containing the XML data. |
- Returns
- A pointer to the created XMLObject.
- Exceptions
-
| std::runtime_error | if parsing the XML fails. |
Definition at line 75 of file XMLObject.cpp.
◆ createObject()
| XMLObject * XML::XMLObject::createObject |
( |
const xercesc::DOMElement * | element | ) |
|
|
staticprotected |
◆ find()
template<typename T, typename Self>
| auto XML::XMLObject::find |
( |
this Self && | self | ) |
|
|
inline |
- Returns
- A vector of references to descendants of type T, const-qualified to match the receiver.
Definition at line 212 of file XMLObject.h.
◆ format()
| std::string XML::XMLObject::format |
( |
std::string | indentation = "\t", |
|
|
unsigned int | depth = 0 ) const |
- Returns
- A formatted string representing the XMLObject.
Definition at line 184 of file XMLObject.cpp.
◆ get()
template<typename T, typename Self>
| auto * XML::XMLObject::get |
( |
this Self && | self | ) |
|
|
inline |
- Parameters
-
| self | The object the call is made on; its const-ness determines that of the result. |
- Returns
- A pointer to the casted object, const-qualified to match the receiver.
- Exceptions
-
| std::runtime_error | if the cast fails. |
Definition at line 182 of file XMLObject.h.
◆ getChildren()
template<typename T, typename Self>
| auto XML::XMLObject::getChildren |
( |
this Self && | self | ) |
|
|
inline |
- Parameters
-
| self | The object the call is made on; its const-ness determines that of the result. |
- Returns
- A vector of references to the children of type T, const-qualified to match the receiver.
Definition at line 283 of file XMLObject.h.
◆ getChildrenByName()
template<typename Self>
| auto XML::XMLObject::getChildrenByName |
( |
this Self && | self, |
|
|
const ElementName & | name ) |
|
inline |
- Parameters
-
| self | The object the call is made on; its const-ness determines that of the result. |
| name | The name of the child elements without namespace prefix. |
- Returns
- A vector of references to the children with the specified element name, const-qualified to match the receiver.
Definition at line 337 of file XMLObject.h.
◆ getOptionalAttributeByName()
template<typename Self>
| auto XML::XMLObject::getOptionalAttributeByName |
( |
this Self && | self, |
|
|
const AttributeName & | name ) |
|
inline |
- Parameters
-
| self | The object the call is made on; its const-ness determines that of the result. |
| name | The name of the attribute without namespace prefix. |
- Returns
- An optional reference to the optional attribute (const-qualified to match the receiver) if found, or std::nullopt if the optional attribute is not found.
Definition at line 373 of file XMLObject.h.
◆ getOptionalChild()
template<typename T, typename Self>
| auto XML::XMLObject::getOptionalChild |
( |
this Self && | self | ) |
|
|
inline |
- Parameters
-
| self | The object the call is made on; its const-ness determines that of the result. |
- Returns
- An optional reference to the optional child (const-qualified to match the receiver) if found, or std::nullopt if the optional child is not found.
Definition at line 266 of file XMLObject.h.
◆ getOptionalChildByName()
template<typename Self>
| auto XML::XMLObject::getOptionalChildByName |
( |
this Self && | self, |
|
|
const ElementName & | name ) |
|
inline |
- Parameters
-
| self | The object the call is made on; its const-ness determines that of the result. |
| name | The name of the child element without namespace prefix. |
- Returns
- An optional reference to the optional child (const-qualified to match the receiver) if found, or std::nullopt if the optional child is not found.
Definition at line 319 of file XMLObject.h.
◆ getRequiredAttributeByName()
template<typename Self>
| auto & XML::XMLObject::getRequiredAttributeByName |
( |
this Self && | self, |
|
|
const AttributeName & | name ) |
|
inline |
- Parameters
-
| self | The object the call is made on; its const-ness determines that of the result. |
| name | The name of the attribute without namespace prefix. |
- Returns
- A reference to the required attribute, const-qualified to match the receiver.
- Exceptions
-
| std::runtime_error | if the required attribute is not found. |
Definition at line 356 of file XMLObject.h.
◆ getRequiredChild()
template<typename T, typename Self>
| auto & XML::XMLObject::getRequiredChild |
( |
this Self && | self | ) |
|
|
inline |
- Parameters
-
| self | The object the call is made on; its const-ness determines that of the result. |
- Returns
- A reference to the required child, const-qualified to match the receiver.
- Exceptions
-
| std::runtime_error | if the required child is not found. |
Definition at line 250 of file XMLObject.h.
◆ getRequiredChildByName()
template<typename Self>
| auto & XML::XMLObject::getRequiredChildByName |
( |
this Self && | self, |
|
|
const ElementName & | name ) |
|
inline |
- Parameters
-
| self | The object the call is made on; its const-ness determines that of the result. |
| name | The name of the child element without namespace prefix. |
- Returns
- A reference to the required child, const-qualified to match the receiver.
- Exceptions
-
| std::runtime_error | if the required child is not found. |
Definition at line 302 of file XMLObject.h.
◆ is()
template<typename T, typename Self>
| auto * XML::XMLObject::is |
( |
this Self && | self | ) |
|
|
inline |
◆ stringify()
| std::string XML::XMLObject::stringify |
( |
| ) |
const |
- Returns
- The string representation of the XMLObject.
Definition at line 169 of file XMLObject.cpp.
◆ createInstance
◆ attributes
◆ children
◆ className
◆ defaults
◆ elementName
◆ factory
◆ prefix
◆ textContent
◆ xmlns
The documentation for this class was generated from the following files: