bpmn++
A BPMN parser library, written in C++
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 129 of file XMLObject.h.

#include <XMLObject.h>

Inheritance diagram for XML::XMLObject:

Public Member Functions

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.

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.

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)

Static Protected Member Functions

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.

Constructor & Destructor Documentation

◆ ~XMLObject()

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

Definition at line 159 of file XMLObject.h.

◆ XMLObject()

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

Definition at line 129 of file XMLObject.cpp.

Member Function Documentation

◆ createFromFile()

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 81 of file XMLObject.cpp.

◆ createFromStream()

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 47 of file XMLObject.cpp.

◆ createFromString()

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 75 of file XMLObject.cpp.

◆ createObject()

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

Definition at line 119 of file XMLObject.cpp.

◆ 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
selfThe 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_errorif 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
selfThe 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
selfThe object the call is made on; its const-ness determines that of the result.
nameThe 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
selfThe object the call is made on; its const-ness determines that of the result.
nameThe 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
selfThe 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
selfThe object the call is made on; its const-ness determines that of the result.
nameThe 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
selfThe object the call is made on; its const-ness determines that of the result.
nameThe name of the attribute without namespace prefix.
Returns
A reference to the required attribute, const-qualified to match the receiver.
Exceptions
std::runtime_errorif 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
selfThe 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_errorif 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
selfThe object the call is made on; its const-ness determines that of the result.
nameThe name of the child element without namespace prefix.
Returns
A reference to the required child, const-qualified to match the receiver.
Exceptions
std::runtime_errorif 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

Definition at line 172 of file XMLObject.h.

◆ stringify()

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

Definition at line 169 of file XMLObject.cpp.

◆ createInstance

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

Definition at line 86 of file XMLObject.h.

Member Data Documentation

◆ attributes

Attributes XML::XMLObject::attributes

Definition at line 226 of file XMLObject.h.

◆ children

Children XML::XMLObject::children

Definition at line 225 of file XMLObject.h.

◆ className

const ClassName XML::XMLObject::className

Definition at line 220 of file XMLObject.h.

◆ defaults

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

Definition at line 227 of file XMLObject.h.

◆ elementName

ElementName XML::XMLObject::elementName

Definition at line 222 of file XMLObject.h.

◆ factory

Factory XML::XMLObject::factory
inlinestaticprotected

Definition at line 169 of file XMLObject.h.

◆ prefix

Namespace XML::XMLObject::prefix

Definition at line 221 of file XMLObject.h.

◆ textContent

TextContent XML::XMLObject::textContent

Definition at line 224 of file XMLObject.h.

◆ xmlns

Namespace XML::XMLObject::xmlns

Definition at line 219 of file XMLObject.h.


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