PLCnext API Documentation  20.6.0.30321
Public Member Functions | Static Public Member Functions | List of all members
Arp::System::Commons::Xml::XmlReader Class Reference

Class to read an XML File. Non buffered reader, can only read forward More...

#include <XmlReader.hpp>

Public Member Functions

 XmlReader (void)
 Default contructor. More...
 
 XmlReader (XmlReader &&arg)
 Move contructor. More...
 
 ~XmlReader (void)
 Destructs this instance and frees all resources. More...
 
String GetElementLocalName (void)
 Reads the local name of the current active element More...
 
long GetLineNumber ()
 Gets the actual line number of this XML reader More...
 
const StringGetDocumentFileName ()
 Gets the current document filename of this XML reader More...
 
bool Read ()
 Reads to the next element inside the xml file More...
 
XmlNodeType GetCurrentNodeType ()
 gets the type of the current xml element More...
 
bool IsEmptyElement ()
 test if the current element is an empty element More...
 
int GetCurrentDepth ()
 gets the current depth of the current element inside the xml document More...
 
bool Skip ()
 skips the current element with its whole subtree (use SkipElement() because naming is more clear) More...
 
bool SkipElement ()
 skips the current element with its whole subtree More...
 
bool SkipElementContent ()
 skips the content of current element with its whole subtree but does not read end element tag More...
 
bool MoveToElement ()
 Moves the position of the current instance to the node that contains the current Attribute node. More...
 
bool ReadToFollowing (const String &name)
 reads the xml file until an element with name is reached or end of file is reached More...
 
bool ReadToDescendant (const String &name)
 reads the xml file until an element with name is reached or the current element is closed reads to the next element with name included in current element More...
 
bool ReadToNextSibling (const String &name)
 reads to the next element with name which is a sibling of the current element More...
 
void ReadStartElement (const char *elementName=nullptr)
 reads to the next element and test if this is a start element with the given name More...
 
bool TryReadStartElement (const char *elementName=nullptr)
 trys to read the next element and test if this is a start element with the given name More...
 
bool TryReadStartElement (String &elementName, bool conditioned=true)
 trys to read the next element and returns the read element name as out argument More...
 
void ReadEndElement (void)
 reads until the next end element is reached skips over an empty element More...
 
bool TryReadEndElement (void)
 tries to read until the next end element is reached skips over an empty element More...
 
String ReadElementContent (void)
 reads the content of the current element if a CDATA section is found, the CDATA enclosure is removed More...
 
template<class T >
ReadElementContent ()
 reads the content of the current element if a CDATA section is found, the CDATA enclosure is removed More...
 
template<class T >
GetAttributeValue (const char *attributeName)
 reads an attribute value from the current element More...
 
template<class T >
Enum< T > GetAttributeValueEnum (const char *attributeName)
 reads an attribute value from the current element and converts the String to Enum<T> More...
 
template<class T >
bool TryGetAttributeValueEnum (const char *attributeName, Enum< T > &value)
 trys reads an attribute value from the current element and converts the String to Enum<T> More...
 
template<class T >
bool TryGetAttributeValueEnum (const char *attributeName, T defaultValue, Enum< T > &value)
 tries to read an attribute value from the current element as enum if the attribute was not found or the conversation fails a defaultValue is used More...
 
template<class T >
GetAttributeValueDuration (const char *attributeName)
 reads an attribute value from the current element and converts the String to std::chrono::duration i.e. Microseconds More...
 
template<class T >
bool TryGetAttributeValueDuration (const char *attributeName, T &value)
 trys reads an attribute value from the current element and converts the String to std::chrono::duration i.e. Microseconds More...
 
template<class T >
bool TryGetAttributeValueDuration (const char *attributeName, T defaultValue, T &value)
 tries to read an attribute value from the current element as std::crono::duration if the attribute was not found or the conversation fails a defaultValue is used More...
 
template<class T >
bool TryGetAttributeValue (const char *attributeName, T &value)
 tries to read an attribute value from the current element More...
 
template<class T >
bool TryGetAttributeValue (const char *attributeName, T defaultValue, T &value)
 tries to read an attribute value from the current element if the attribute was not found or the conversation fails a defaultValue is used More...
 
void EnableValidationException ()
 
void DisableValidationException ()
 
template<typename... Args>
XmlException CreateException (const char *message, const Args &... args)
 Creates an exception by prefixing the given message with current doc name and line number More...
 
template<>
bool TryGetAttributeValue (const char *, bool &value)
 
template<>
bool TryGetAttributeValue (const char *attributeName, String &value)
 
template<>
bool TryGetAttributeValue (const char *attributeName, Chrono::Duration &value)
 
template<>
bool TryGetAttributeValue (const char *attributeName, uint8 &value)
 
template<>
bool TryGetAttributeValue (const char *attributeName, int8 &value)
 

Static Public Member Functions

static XmlReader Create (const String &filename)
 Creates a new Instance of the XmlReader More...
 
static bool TryCreate (const String &filename, XmlReader &reader)
 Tries to creates a new Instance of the XmlReader More...
 
static XmlReader Create (const String &filename, const String &xsdFile)
 Creates a new Instance of the XmlReader and enables Schema validation with the XSD schema at xsdFile More...
 
static XmlReader CreateForString (const String &buffer)
 Creates a new Instance of the XmlReader reading from an in memory buffer More...
 

Detailed Description

Class to read an XML File. Non buffered reader, can only read forward

Constructor & Destructor Documentation

◆ XmlReader() [1/2]

Arp::System::Commons::Xml::XmlReader::XmlReader ( void  )

Default contructor.

◆ XmlReader() [2/2]

Arp::System::Commons::Xml::XmlReader::XmlReader ( XmlReader &&  arg)

Move contructor.

◆ ~XmlReader()

Arp::System::Commons::Xml::XmlReader::~XmlReader ( void  )

Destructs this instance and frees all resources.

Member Function Documentation

◆ Create() [1/2]

static XmlReader Arp::System::Commons::Xml::XmlReader::Create ( const String filename)
static

Creates a new Instance of the XmlReader

Parameters
filenameThe Filename the writer uses to write the xml data
Exceptions
XmlException

◆ Create() [2/2]

static XmlReader Arp::System::Commons::Xml::XmlReader::Create ( const String filename,
const String xsdFile 
)
static

Creates a new Instance of the XmlReader and enables Schema validation with the XSD schema at xsdFile

Parameters
filenameThe Filename the writer uses to write the xml data
xsdFilePath to the XSD File with the XMl schema. the scheme is verified as the xml file is processed, so in every read call an schema error can occur
Exceptions
XmlException

◆ CreateException()

template<typename... Args>
XmlException Arp::System::Commons::Xml::XmlReader::CreateException ( const char *  message,
const Args &...  args 
)
inline

Creates an exception by prefixing the given message with current doc name and line number

Parameters
messageThe message format of the exception message
argsThe fomrat arguments to be inserted into message.

◆ CreateForString()

static XmlReader Arp::System::Commons::Xml::XmlReader::CreateForString ( const String buffer)
static

Creates a new Instance of the XmlReader reading from an in memory buffer

Parameters
bufferReference to the buffer to read from
Exceptions
XmlException

◆ GetAttributeValue()

template<class T >
T Arp::System::Commons::Xml::XmlReader::GetAttributeValue ( const char *  attributeName)
inline

reads an attribute value from the current element

Parameters
attributeNamethe name of the attribute to read
Returns
the value of the attribute with attributeName converted to T
Exceptions
XmlExceptionif the attribute was not found, or the conversion failed

◆ GetAttributeValueDuration()

template<class T >
T Arp::System::Commons::Xml::XmlReader::GetAttributeValueDuration ( const char *  attributeName)
inline

reads an attribute value from the current element and converts the String to std::chrono::duration i.e. Microseconds

Parameters
attributeNamethe name of the enum attribute to read
Returns
the value of the enum attribute with attributeName converted to std::chrono::duration
Exceptions
XmlExceptionif the attribute was not found, or the conversion failed

◆ GetAttributeValueEnum()

template<class T >
Enum<T> Arp::System::Commons::Xml::XmlReader::GetAttributeValueEnum ( const char *  attributeName)
inline

reads an attribute value from the current element and converts the String to Enum<T>

Parameters
attributeNamethe name of the enum attribute to read
Returns
the value of the enum attribute with attributeName converted to Enum<T>
Exceptions
XmlExceptionif the attribute was not found, or the conversion failed

◆ GetCurrentDepth()

int Arp::System::Commons::Xml::XmlReader::GetCurrentDepth ( )

gets the current depth of the current element inside the xml document

Returns
the current depth of the current element inside the xml document

◆ GetCurrentNodeType()

XmlNodeType Arp::System::Commons::Xml::XmlReader::GetCurrentNodeType ( )

gets the type of the current xml element

Returns
The node type of the current xml node

◆ GetDocumentFileName()

const String & Arp::System::Commons::Xml::XmlReader::GetDocumentFileName ( )
inline

Gets the current document filename of this XML reader

Returns
The name of the actually parsed deocument

◆ GetElementLocalName()

String Arp::System::Commons::Xml::XmlReader::GetElementLocalName ( void  )

Reads the local name of the current active element

Returns
the local name of the current active element

◆ GetLineNumber()

long Arp::System::Commons::Xml::XmlReader::GetLineNumber ( )

Gets the actual line number of this XML reader

Returns
The current line number

◆ IsEmptyElement()

bool Arp::System::Commons::Xml::XmlReader::IsEmptyElement ( )

test if the current element is an empty element

Returns
true if the current element is an empty element, false otherwise

◆ MoveToElement()

bool Arp::System::Commons::Xml::XmlReader::MoveToElement ( )

Moves the position of the current instance to the node that contains the current Attribute node.

Returns
true if the position was moved, false if the position was not moved

◆ Read()

bool Arp::System::Commons::Xml::XmlReader::Read ( )

Reads to the next element inside the xml file

Returns
true if the read was successful, false if the end of the file was reached

◆ ReadElementContent() [1/2]

String Arp::System::Commons::Xml::XmlReader::ReadElementContent ( void  )

reads the content of the current element if a CDATA section is found, the CDATA enclosure is removed

Returns
the element content as Arp::String

◆ ReadElementContent() [2/2]

template<class T >
T Arp::System::Commons::Xml::XmlReader::ReadElementContent ( void  )
inline

reads the content of the current element if a CDATA section is found, the CDATA enclosure is removed

Returns
the element content converted to T with boost::lexical_cast<T>

◆ ReadEndElement()

void Arp::System::Commons::Xml::XmlReader::ReadEndElement ( void  )

reads until the next end element is reached skips over an empty element

◆ ReadStartElement()

void Arp::System::Commons::Xml::XmlReader::ReadStartElement ( const char *  elementName = nullptr)

reads to the next element and test if this is a start element with the given name

Parameters
elementNamename against which the name of the start element is tested, if elementName is null the test is omitted

◆ ReadToDescendant()

bool Arp::System::Commons::Xml::XmlReader::ReadToDescendant ( const String name)

reads the xml file until an element with name is reached or the current element is closed reads to the next element with name included in current element

Parameters
namename of the descendant element to move to
Returns
true if an descendant element with name was found, false if no descendant element with name was found or the end of the file is reached

◆ ReadToFollowing()

bool Arp::System::Commons::Xml::XmlReader::ReadToFollowing ( const String name)

reads the xml file until an element with name is reached or end of file is reached

Parameters
namename of the element to move to
Returns
true if an element with name was found, false if end of file is reached

◆ ReadToNextSibling()

bool Arp::System::Commons::Xml::XmlReader::ReadToNextSibling ( const String name)

reads to the next element with name which is a sibling of the current element

Parameters
namename of the sibling element to move to
Returns
true if an sibling element with name was found, false if no sibling element with name was found or the end of the file is reached

◆ Skip()

bool Arp::System::Commons::Xml::XmlReader::Skip ( )

skips the current element with its whole subtree (use SkipElement() because naming is more clear)

Returns
true if skip was successful, false if the end of the file was reached

◆ SkipElement()

bool Arp::System::Commons::Xml::XmlReader::SkipElement ( )

skips the current element with its whole subtree

Returns
true if skip was successful, false if the end of the file was reached

◆ SkipElementContent()

bool Arp::System::Commons::Xml::XmlReader::SkipElementContent ( )

skips the content of current element with its whole subtree but does not read end element tag

Returns
true if skip was successful, false if the current node is not an element

◆ TryCreate()

static bool Arp::System::Commons::Xml::XmlReader::TryCreate ( const String filename,
XmlReader reader 
)
static

Tries to creates a new Instance of the XmlReader

Parameters
filenameThe Filename the writer uses to write the xml data
Exceptions
XmlException

◆ TryGetAttributeValue() [1/2]

template<class T >
bool Arp::System::Commons::Xml::XmlReader::TryGetAttributeValue ( const char *  attributeName,
T &  value 
)
inline

tries to read an attribute value from the current element

Parameters
attributeNamethe name of the attribute to read
valuewhere to store the value of the attribute
Returns
true if the attribute was read successful, false if the attribute was not found or the conversation failed

◆ TryGetAttributeValue() [2/2]

template<class T >
bool Arp::System::Commons::Xml::XmlReader::TryGetAttributeValue ( const char *  attributeName,
defaultValue,
T &  value 
)
inline

tries to read an attribute value from the current element if the attribute was not found or the conversation fails a defaultValue is used

Parameters
attributeNamethe name of the attribute to read
defaultValuethe default value to use in case of an error
valuewhere to store the value of the attribute
Returns
true if the attribute was read successful, false if the attribute was not found or the conversation failed

◆ TryGetAttributeValueDuration() [1/2]

template<class T >
bool Arp::System::Commons::Xml::XmlReader::TryGetAttributeValueDuration ( const char *  attributeName,
T &  value 
)
inline

trys reads an attribute value from the current element and converts the String to std::chrono::duration i.e. Microseconds

Parameters
attributeNamethe name of the enum attribute to read
valuethe value of the enum attribute with attributeName converted to std::chrono::duration
Returns
true if attribute was found and could be converted false otherwise

◆ TryGetAttributeValueDuration() [2/2]

template<class T >
bool Arp::System::Commons::Xml::XmlReader::TryGetAttributeValueDuration ( const char *  attributeName,
defaultValue,
T &  value 
)
inline

tries to read an attribute value from the current element as std::crono::duration if the attribute was not found or the conversation fails a defaultValue is used

Parameters
attributeNamethe name of the attribute to read
defaultValuethe default value to use in case of an error
valuewhere to store the value of the attribute
Returns
true if the attribute was read successful, false if the attribute was not found or the conversation failed

◆ TryGetAttributeValueEnum() [1/2]

template<class T >
bool Arp::System::Commons::Xml::XmlReader::TryGetAttributeValueEnum ( const char *  attributeName,
Enum< T > &  value 
)
inline

trys reads an attribute value from the current element and converts the String to Enum<T>

Parameters
attributeNamethe name of the enum attribute to read
valuethe value of the enum attribute with attributeName converted to Enum<T>
Returns
true if attribute was found and could be converted false otherwise
Exceptions
XmlExceptionif the attribute was not found, or the conversion failed

◆ TryGetAttributeValueEnum() [2/2]

template<class T >
bool Arp::System::Commons::Xml::XmlReader::TryGetAttributeValueEnum ( const char *  attributeName,
defaultValue,
Enum< T > &  value 
)
inline

tries to read an attribute value from the current element as enum if the attribute was not found or the conversation fails a defaultValue is used

Parameters
attributeNamethe name of the attribute to read
defaultValuethe default value to use in case of an error
valuewhere to store the value of the attribute
Returns
true if the attribute was read successful, false if the attribute was not found or the conversation failed

◆ TryReadEndElement()

bool Arp::System::Commons::Xml::XmlReader::TryReadEndElement ( void  )

tries to read until the next end element is reached skips over an empty element

Returns
true if ReadEndElement is successful, false if ReadEndElement was not successful

◆ TryReadStartElement() [1/2]

bool Arp::System::Commons::Xml::XmlReader::TryReadStartElement ( const char *  elementName = nullptr)

trys to read the next element and test if this is a start element with the given name

Parameters
elementNamename against which the name of the start element is tested, if elementName is null the test is omitted
Returns
true if ReadStartElement is successful, false if ReadStartElement was not successful

◆ TryReadStartElement() [2/2]

bool Arp::System::Commons::Xml::XmlReader::TryReadStartElement ( String elementName,
bool  conditioned = true 
)

trys to read the next element and returns the read element name as out argument

Parameters
elementNamethe current element name if a start element tag could be read.
Returns
true if a start element tag could be read, otherwise false.

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