BPMN-OS
BPMN for optimization and simulation
Loading...
Searching...
No Matches
XML::XMLObject Class Reference

A class representing a node in an XML-tree. More...

Detailed Description

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 <bpmn++.h>

Inheritance diagram for XML::XMLObject:

Public Member Functions

virtual ~XMLObject ()
 
template<typename T >
T * is ()
 Returns a pointer of type T of the object.
 
template<typename T >
const T * is () const
 
template<typename T >
T * get ()
 Attempt to cast the current instance to the specified type T.
 
template<typename T >
const T * get () const
 Attempt to cast the current instance to the specified type T.
 
template<typename T >
std::vector< std::reference_wrapper< T > > find ()
 Find all descendants of type T.
 
template<typename T >
std::vector< std::reference_wrapper< const T > > find () const
 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 formated string representing the XMLObject including its children.
 
template<typename T >
T & getRequiredChild ()
 Get a required child of type T.
 
template<typename T >
std::optional< std::reference_wrapper< T > > getOptionalChild ()
 Get an optional child of type T.
 
template<typename T >
std::vector< std::reference_wrapper< T > > getChildren ()
 Get all children of type T.
 
XMLObjectgetRequiredChildByName (const ElementName &elementName)
 Get a required child with the specified element name.
 
std::optional< std::reference_wrapper< XMLObject > > getOptionalChildByName (const ElementName &elementName)
 Get the optional child with the specified element name.
 
std::vector< std::reference_wrapper< XMLObject > > getChildrenByName (const ElementName &elementName)
 Get all children with the specified element name.
 
AttributegetRequiredAttributeByName (const AttributeName &attributeName)
 Get a required attribute with the specified attribute name.
 
std::optional< std::reference_wrapper< Attribute > > getOptionalAttributeByName (const AttributeName &attributeName)
 Get an optional attribute with the specified attribute name.
 
virtual ~XMLObject ()
 
template<typename T >
T * is ()
 Returns a pointer of type T of the object.
 
template<typename T >
const T * is () const
 
template<typename T >
T * get ()
 Attempt to cast the current instance to the specified type T.
 
template<typename T >
const T * get () const
 Attempt to cast the current instance to the specified type T.
 
template<typename T >
std::vector< std::reference_wrapper< T > > find ()
 Find all descendants of type T.
 
template<typename T >
std::vector< std::reference_wrapper< const T > > find () const
 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 formated string representing the XMLObject including its children.
 
template<typename T >
T & getRequiredChild ()
 Get a required child of type T.
 
template<typename T >
std::optional< std::reference_wrapper< T > > getOptionalChild ()
 Get an optional child of type T.
 
template<typename T >
std::vector< std::reference_wrapper< T > > getChildren ()
 Get all children of type T.
 
XMLObjectgetRequiredChildByName (const ElementName &elementName)
 Get a required child with the specified element name.
 
std::optional< std::reference_wrapper< XMLObject > > getOptionalChildByName (const ElementName &elementName)
 Get the optional child with the specified element name.
 
std::vector< std::reference_wrapper< XMLObject > > getChildrenByName (const ElementName &elementName)
 Get all children with the specified element name.
 
AttributegetRequiredAttributeByName (const AttributeName &attributeName)
 Get a required attribute with the specified attribute name.
 
std::optional< std::reference_wrapper< Attribute > > getOptionalAttributeByName (const AttributeName &attributeName)
 Get an optional attribute with the specified attribute name.
 

Static Public Member Functions

static XMLObjectcreateFromStream (std::istream &xmlStream)
 Create an XMLObject from the input stream.
 
static XMLObjectcreateFromString (const std::string &xmlString)
 Create an XMLObject from a string representation of XML.
 
static XMLObjectcreateFromFile (const std::string &filename)
 Create an XMLObject from an XML file.
 
static XMLObjectcreateFromStream (std::istream &xmlStream)
 Create an XMLObject from the input stream.
 
static XMLObjectcreateFromString (const std::string &xmlString)
 Create an XMLObject from a string representation of XML.
 
static XMLObjectcreateFromFile (const std::string &filename)
 Create an XMLObject from an XML file.
 

Public Attributes

Namespace xmlns
 
const ClassName className
 
Namespace prefix
 
ElementName elementName
 
TextContent textContent
 Textual content of XML element without children.
 
Children children
 Child nodes of the XML element.
 
Attributes attributes
 

Static Public Attributes

static const Attributes defaults = {}
 Attributes of the XML element.
 

Protected Member Functions

 XMLObject (const Namespace &xmlns, const ClassName &className, const xercesc::DOMElement *element, const Attributes &defaultAttributes)
 
 XMLObject (const Namespace &xmlns, const ClassName &className, const xercesc::DOMElement *element, const Attributes &defaultAttributes)
 

Static Protected Member Functions

static XMLObjectcreateObject (const xercesc::DOMElement *element)
 
static XMLObjectcreateObject (const xercesc::DOMElement *element)
 

Static Protected Attributes

static Factory factory
 

Friends

template<typename T >
XMLObjectcreateInstance (const Namespace &xmlns, const ClassName &className, const xercesc::DOMElement *element)
 Template function used to store in factory.
 
template<typename T >
XMLObjectcreateInstance (const Namespace &xmlns, const ClassName &className, const xercesc::DOMElement *element)
 Template function used to store in factory.
 

Constructor & Destructor Documentation

◆ ~XMLObject() [1/2]

virtual XML::XMLObject::~XMLObject ( )
inlinevirtual

Definition at line 146 of file bpmn++.h.

◆ XMLObject() [1/2]

XML::XMLObject::XMLObject ( const Namespace & xmlns,
const ClassName & className,
const xercesc::DOMElement * element,
const Attributes & defaultAttributes )
protected

Definition at line 123 of file XMLObject.cpp.

◆ ~XMLObject() [2/2]

virtual XML::XMLObject::~XMLObject ( )
inlinevirtual

Definition at line 145 of file XMLObject.h.

◆ XMLObject() [2/2]

XML::XMLObject::XMLObject ( const Namespace & xmlns,
const ClassName & className,
const xercesc::DOMElement * element,
const Attributes & defaultAttributes )
protected

Member Function Documentation

◆ createFromFile() [1/2]

static XMLObject * XML::XMLObject::createFromFile ( const std::string & filename)
static
Parameters
filenameThe path to the XML file.
Returns
A pointer to the created XMLObject.
Exceptions
std::runtime_errorif loading the file or parsing the XML fails.

◆ createFromFile() [2/2]

XMLObject * XML::XMLObject::createFromFile ( const std::string & filename)
static
Parameters
filenameThe path to the XML file.
Returns
A pointer to the created XMLObject.
Exceptions
std::runtime_errorif loading the file or parsing the XML fails.

Definition at line 80 of file XMLObject.cpp.

◆ createFromStream() [1/2]

static XMLObject * XML::XMLObject::createFromStream ( std::istream & xmlStream)
static
Parameters
xmlStreamThe input stream containing the XML data.
Returns
A pointer to the created XMLObject.
Exceptions
std::runtime_errorif parsing the XML fails.

◆ createFromStream() [2/2]

XMLObject * XML::XMLObject::createFromStream ( std::istream & xmlStream)
static
Parameters
xmlStreamThe input stream containing the XML data.
Returns
A pointer to the created XMLObject.
Exceptions
std::runtime_errorif parsing the XML fails.

Definition at line 46 of file XMLObject.cpp.

◆ createFromString() [1/2]

static XMLObject * XML::XMLObject::createFromString ( const std::string & xmlString)
static
Parameters
xmlStringThe string containing the XML data.
Returns
A pointer to the created XMLObject.
Exceptions
std::runtime_errorif parsing the XML fails.

◆ createFromString() [2/2]

XMLObject * XML::XMLObject::createFromString ( const std::string & xmlString)
static
Parameters
xmlStringThe string containing the XML data.
Returns
A pointer to the created XMLObject.
Exceptions
std::runtime_errorif parsing the XML fails.

Definition at line 74 of file XMLObject.cpp.

◆ createObject() [1/2]

static XMLObject * XML::XMLObject::createObject ( const xercesc::DOMElement * element)
staticprotected

◆ createObject() [2/2]

XMLObject * XML::XMLObject::createObject ( const xercesc::DOMElement * element)
staticprotected

Definition at line 113 of file XMLObject.cpp.

◆ find() [1/4]

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/4]

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 223 of file bpmn++.h.

◆ find() [3/4]

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.

◆ find() [4/4]

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 236 of file bpmn++.h.

◆ format() [1/2]

std::string XML::XMLObject::format ( std::string indentation = "\t",
unsigned int depth = 0 ) const
Returns
A formated string representing the XMLObject.

◆ format() [2/2]

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/4]

template<typename T >
T * XML::XMLObject::get ( )
inline
Returns
A pointer to the casted object.
Exceptions
std::runtime_errorif the cast fails.

Definition at line 171 of file XMLObject.h.

◆ get() [2/4]

template<typename T >
T * XML::XMLObject::get ( )
inline
Returns
A pointer to the casted object.
Exceptions
std::runtime_errorif the cast fails.

Definition at line 172 of file bpmn++.h.

◆ get() [3/4]

template<typename T >
const T * XML::XMLObject::get ( ) const
inline
Returns
A pointer to the casted object.
Exceptions
std::runtime_errorif the cast fails.

Definition at line 184 of file XMLObject.h.

◆ get() [4/4]

template<typename T >
const T * XML::XMLObject::get ( ) const
inline
Returns
A pointer to the casted object.
Exceptions
std::runtime_errorif the cast fails.

Definition at line 185 of file bpmn++.h.

◆ getChildren() [1/2]

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.

◆ getChildren() [2/2]

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 302 of file bpmn++.h.

◆ getChildrenByName() [1/2]

std::vector< std::reference_wrapper< XMLObject > > XML::XMLObject::getChildrenByName ( const ElementName & elementName)
Parameters
elementNameThe name of the child elements without namespace prefix.
Returns
A vector of references to the children with the specified element name.

◆ getChildrenByName() [2/2]

std::vector< std::reference_wrapper< XMLObject > > XML::XMLObject::getChildrenByName ( const ElementName & elementName)
Parameters
elementNameThe 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() [1/2]

std::optional< std::reference_wrapper< Attribute > > XML::XMLObject::getOptionalAttributeByName ( const AttributeName & attributeName)
Parameters
attributeNameThe 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.

◆ getOptionalAttributeByName() [2/2]

std::optional< std::reference_wrapper< Attribute > > XML::XMLObject::getOptionalAttributeByName ( const AttributeName & attributeName)
Parameters
attributeNameThe 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() [1/2]

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.

◆ getOptionalChild() [2/2]

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 288 of file bpmn++.h.

◆ getOptionalChildByName() [1/2]

std::optional< std::reference_wrapper< XMLObject > > XML::XMLObject::getOptionalChildByName ( const ElementName & elementName)
Parameters
elementNameThe 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.

◆ getOptionalChildByName() [2/2]

std::optional< std::reference_wrapper< XMLObject > > XML::XMLObject::getOptionalChildByName ( const ElementName & elementName)
Parameters
elementNameThe 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() [1/2]

Attribute & XML::XMLObject::getRequiredAttributeByName ( const AttributeName & attributeName)
Parameters
attributeNameThe name of the attribute without namespace prefix.
Returns
A reference to the required attribute.
Exceptions
std::runtime_errorif the required attribute is not found.

◆ getRequiredAttributeByName() [2/2]

Attribute & XML::XMLObject::getRequiredAttributeByName ( const AttributeName & attributeName)
Parameters
attributeNameThe name of the attribute without namespace prefix.
Returns
A reference to the required attribute.
Exceptions
std::runtime_errorif the required attribute is not found.

Definition at line 187 of file XMLObject.cpp.

◆ getRequiredChild() [1/2]

template<typename T >
T & XML::XMLObject::getRequiredChild ( )
inline
Returns
A reference to the required child.
Exceptions
std::runtime_errorif the required child is not found.

Definition at line 272 of file XMLObject.h.

◆ getRequiredChild() [2/2]

template<typename T >
T & XML::XMLObject::getRequiredChild ( )
inline
Returns
A reference to the required child.
Exceptions
std::runtime_errorif the required child is not found.

Definition at line 273 of file bpmn++.h.

◆ getRequiredChildByName() [1/2]

XMLObject & XML::XMLObject::getRequiredChildByName ( const ElementName & elementName)
Parameters
elementNameThe name of the child element without namespace prefix.
Returns
A reference to the required child.
Exceptions
std::runtime_errorif the required child is not found.

◆ getRequiredChildByName() [2/2]

XMLObject & XML::XMLObject::getRequiredChildByName ( const ElementName & elementName)
Parameters
elementNameThe name of the child element without namespace prefix.
Returns
A reference to the required child.
Exceptions
std::runtime_errorif the required child is not found.

Definition at line 159 of file XMLObject.cpp.

◆ is() [1/4]

template<typename T >
T * XML::XMLObject::is ( )
inline

Definition at line 158 of file XMLObject.h.

◆ is() [2/4]

template<typename T >
T * XML::XMLObject::is ( )
inline

Definition at line 159 of file bpmn++.h.

◆ is() [3/4]

template<typename T >
const T * XML::XMLObject::is ( ) const
inline

Definition at line 162 of file XMLObject.h.

◆ is() [4/4]

template<typename T >
const T * XML::XMLObject::is ( ) const
inline

Definition at line 163 of file bpmn++.h.

◆ stringify() [1/2]

std::string XML::XMLObject::stringify ( ) const
Returns
The string representation of the XMLObject.

◆ stringify() [2/2]

std::string XML::XMLObject::stringify ( ) const
Returns
The string representation of the XMLObject.

Definition at line 207 of file XMLObject.cpp.

Friends And Related Symbol Documentation

◆ createInstance [1/2]

template<typename T >
XMLObject * createInstance ( const Namespace & xmlns,
const ClassName & className,
const xercesc::DOMElement * element )
friend

Definition at line 85 of file bpmn++.h.

◆ createInstance [2/2]

template<typename T >
XMLObject * createInstance ( const Namespace & xmlns,
const ClassName & className,
const xercesc::DOMElement * element )
friend

Definition at line 85 of file bpmn++.h.

Member Data Documentation

◆ attributes

Attributes XML::XMLObject::attributes

Definition at line 250 of file bpmn++.h.

◆ children

Children XML::XMLObject::children

Definition at line 249 of file bpmn++.h.

◆ className

const ClassName XML::XMLObject::className

Definition at line 244 of file bpmn++.h.

◆ defaults

static const Attributes XML::XMLObject::defaults = {}
inlinestatic

Definition at line 251 of file bpmn++.h.

◆ elementName

ElementName XML::XMLObject::elementName

Definition at line 246 of file bpmn++.h.

◆ factory

static Factory XML::XMLObject::factory
inlinestaticprotected

Definition at line 156 of file bpmn++.h.

◆ prefix

Namespace XML::XMLObject::prefix

Definition at line 245 of file bpmn++.h.

◆ textContent

TextContent XML::XMLObject::textContent

Definition at line 248 of file bpmn++.h.

◆ xmlns

Namespace XML::XMLObject::xmlns

Definition at line 243 of file bpmn++.h.


The documentation for this class was generated from the following files: