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 115 of file XMLObject.h.
#include <XMLObject.h>
◆ ~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 80 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 46 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 74 of file XMLObject.cpp.
◆ createObject()
XMLObject * XML::XMLObject::createObject |
( |
const xercesc::DOMElement * |
element | ) |
|
|
staticprotected |
◆ find() [1/2]
template<typename T >
std::vector<std::reference_wrapper<T> > XML::XMLObject::find |
( |
| ) |
|
|
inline |
- Returns
- A vector of references to descendants of type T.
Definition at line 222 of file XMLObject.h.
◆ find() [2/2]
template<typename T >
std::vector<std::reference_wrapper<const T> > XML::XMLObject::find |
( |
| ) |
const |
|
inline |
- Returns
- A vector of const references to descendants of type T.
Definition at line 235 of file XMLObject.h.
◆ format()
std::string XML::XMLObject::format |
( |
std::string |
indentation = "\t" , |
|
|
unsigned int |
depth = 0 |
|
) |
| const |
- Returns
- A formated string representing the XMLObject.
Definition at line 222 of file XMLObject.cpp.
◆ get() [1/2]
template<typename T >
T* XML::XMLObject::get |
( |
| ) |
|
|
inline |
- Returns
- A pointer to the casted object.
- Exceptions
-
std::runtime_error | if the cast fails. |
Definition at line 171 of file XMLObject.h.
◆ get() [2/2]
template<typename T >
const T* XML::XMLObject::get |
( |
| ) |
const |
|
inline |
- Returns
- A pointer to the casted object.
- Exceptions
-
std::runtime_error | if the cast fails. |
Definition at line 184 of file XMLObject.h.
◆ getChildren()
template<typename T >
std::vector< std::reference_wrapper<T> > XML::XMLObject::getChildren |
( |
| ) |
|
|
inline |
- Returns
- A vector of references to the children of type T.
Definition at line 301 of file XMLObject.h.
◆ getChildrenByName()
std::vector< std::reference_wrapper< XMLObject > > XML::XMLObject::getChildrenByName |
( |
const ElementName & |
elementName | ) |
|
- Parameters
-
elementName | The name of the child elements without namespace prefix. |
- Returns
- A vector of references to the children with the specified element name.
Definition at line 177 of file XMLObject.cpp.
◆ getOptionalAttributeByName()
std::optional< std::reference_wrapper< Attribute > > XML::XMLObject::getOptionalAttributeByName |
( |
const AttributeName & |
attributeName | ) |
|
- Parameters
-
attributeName | The name of the attribute without namespace prefix. |
- Returns
- An optional containing a reference to the optional attribute if found, or
std::nullopt
if the optional attribute is not found.
Definition at line 197 of file XMLObject.cpp.
◆ getOptionalChild()
template<typename T >
std::optional< std::reference_wrapper<T> > XML::XMLObject::getOptionalChild |
( |
| ) |
|
|
inline |
- Returns
- An optional containing a reference to the optional child if found, or
std::nullopt
if the optional child is not found.
Definition at line 287 of file XMLObject.h.
◆ getOptionalChildByName()
std::optional< std::reference_wrapper< XMLObject > > XML::XMLObject::getOptionalChildByName |
( |
const ElementName & |
elementName | ) |
|
- Parameters
-
elementName | The name of the child element without namespace prefix. |
- Returns
- An optional containing a reference to the optional child if found, or
std::nullopt
if the optional child is not found.
Definition at line 168 of file XMLObject.cpp.
◆ getRequiredAttributeByName()
- Parameters
-
attributeName | The name of the attribute without namespace prefix. |
- Returns
- A reference to the required attribute.
- Exceptions
-
std::runtime_error | if the required attribute is not found. |
Definition at line 187 of file XMLObject.cpp.
◆ getRequiredChild()
template<typename T >
T& XML::XMLObject::getRequiredChild |
( |
| ) |
|
|
inline |
- Returns
- A reference to the required child.
- Exceptions
-
std::runtime_error | if the required child is not found. |
Definition at line 272 of file XMLObject.h.
◆ getRequiredChildByName()
- Parameters
-
elementName | The name of the child element without namespace prefix. |
- Returns
- A reference to the required child.
- Exceptions
-
std::runtime_error | if the required child is not found. |
Definition at line 159 of file XMLObject.cpp.
◆ is() [1/2]
template<typename T >
T* XML::XMLObject::is |
( |
| ) |
|
|
inline |
◆ is() [2/2]
template<typename T >
const T* XML::XMLObject::is |
( |
| ) |
const |
|
inline |
◆ stringify()
std::string XML::XMLObject::stringify |
( |
| ) |
const |
- Returns
- The string representation of the XMLObject.
Definition at line 207 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: