ADTF  3.18.2
cDOMElement

representation for an element of the cDom More...

Public Member Functions

A_UTILS_DEPRECATED() cDOMElement ()
 Default constructor. More...
 
A_UTILS_DEPRECATED() cDOMElement (const cDOMElement &oElement)
 Copy constructor. More...
 
virtual ~cDOMElement ()
 Destructor.
 
cDOMElementoperator= (const cDOMElement &oElement)
 Copy assignment operator. More...
 
tResult Free ()
 Frees all allocated resources. More...
 
const cStringGetName () const
 Returns the name of the element. More...
 
tVoid SetName (const cString &strName)
 Sets the name of the element. More...
 
cDOMElementGetParent ()
 Returns the elements parent element. More...
 
const cDOMElementGetParent () const
 Returns the elements parent element. More...
 
cDOMGetDocument ()
 Returns the document that the element belongs to. More...
 
const cDOMGetDocument () const
 Returns the document that the element belongs to. More...
 
cDOMElementListGetChildren ()
 Returns a list of all child elements of the element. More...
 
const cDOMElementListGetChildren () const
 Returns a list of all child elements of the element. More...
 
const cStringGetData () const
 Returns the data of the element. More...
 
tVoid SetData (const cString &strData)
 Sets the data of the element. More...
 
cDOMAttributesGetAttributes ()
 Returns a map of alle attributes of the element. More...
 
const cDOMAttributesGetAttributes () const
 Returns a map of alle attributes of the element. More...
 
tBool Exists (const cString &strName) const
 Checks if an attribute exists. More...
 
cString GetAttribute (const cString &strName, const cString &strDefault=cString()) const
 Returns the value of an attribute. More...
 
tInt GetAttributeInt (const cString &strName, tInt nDefault=0) const
 Returns the value of an attribute interpreted as an integer. More...
 
tUInt32 GetAttributeUInt32 (const cString &strName, tUInt32 nDefault=0) const
 Returns the value of an attribute interpreted as an integer. More...
 
tBool GetAttributeBool (const cString &strName, tBool bDefault=tFalse) const
 Returns the value of an attribute interpreted as a boolean. More...
 
tFloat64 GetAttributeFloat64 (const cString &strName, tFloat64 fDefault=0.0) const
 Returns the value of an attribute interpreted as a float. More...
 
tVoid SetAttribute (const cString &strName, const cString &strValue)
 Sets an attribute. More...
 
tVoid EraseAttribute (const cString &strName)
 Removes an attribute. More...
 
const cStringGetPath () const
 returns the current path More...
 
tResult FindNode (const tChar *strQuery, cDOMElement *&poElement)
 Finds a node based on a query. More...
 
tResult FindNodes (const tChar *strQuery, cDOMElementRefList &lstElements, tInt32 ui32Flags=0)
 Finds nodes based on a query. More...
 
tResult FromString (const tChar *strXML)
 Creates the element from an xml string. More...
 
cString ToString () const
 Creates an xml representation of the element. More...
 
tResult CreateChild (const cString &strName, cDOMElement *&poChild)
 Creates a new child element. More...
 
tResult InsertChild (const cDOMElement &oChild)
 Adds an existing child element. More...
 
tResult InsertBefore (const cDOMElement &oChild, cDOMElement *pBefore)
 Inserts an existing child element at a specified position. More...
 
cDOMElementGetChild (const cString &strName)
 Find the first child of that name of this element. More...
 
const cDOMElementGetChild (const cString &strName) const
 Find the first child of that name of this element. More...
 
tResult Delete ()
 Removes the element from its parent element. More...
 

Protected Member Functions

tResult Create (const tChar *&ptr, cDOMElement *pParent, cDOM *pDocument, const tChar *pStart=nullptr)
 Parses the DOM element from the input string. More...
 
tVoid CreateChild (const std::list< cString > &lstComment, const tInt &nFlag=0)
 Parses comments from and creates pseudo DOM childs. More...
 
tResult ReadAttributes (const tChar *&ptr, const tChar *pStart=nullptr)
 Parses the attributes from the input string. More...
 
tResult ReadData (const tChar *&ptr, const tChar *pStart=nullptr)
 Parses the data from the input string. More...
 
tBool MatchQuery (const tChar *ptr, tUInt32 &o_nOffset)
 Matches the query with the child attributes. More...
 
tBool MatchAttributes (const tChar *pString)
 Matches the attributes of the DOM child. More...
 
tResult FindNodesImpl (const tChar *strQuery, cDOMElementRefList &lstElements, tBool &bFinished, tUInt32 ui32Flags)
 Find nodes who matches the query string. More...
 
cString ToStringImpl (tUInt32 ui32Flags, tInt nIndentLevel=0) const
 Converts the DOM element into a textual XML like representation. More...
 

Protected Attributes

cDOMm_pDocument
 the complete xml document
 
cDOMElementm_pParent
 the parent element
 
cDOMElementList m_lstChildren
 list of all children
 
cString m_strName
 the name of the element
 
cString m_strPath
 the path to the element
 
cString m_strData
 raw data of the element
 
cDOMAttributes m_mapAttributes
 maps several attributs of the element
 

Static Protected Attributes

static cString m_strEmptyValue
 empty string
 
static cDOMElement m_oNullElement
 empty element
 

Private Member Functions

tResult MergeIncludeNode (cDOMElement &oIncludeNode)
 
tVoid Copy (const cDOMElement &oFromElement, cDOMElement *pParent, cDOM *pDocument, const cString &strPath)
 

Detailed Description

Constructor & Destructor Documentation

◆ cDOMElement() [1/2]

Default constructor.

Deprecated:
Within further releases the cDOM will be completely reworked. API will change !!

◆ cDOMElement() [2/2]

A_UTILS_DEPRECATED() cDOMElement ( const cDOMElement oElement)

Copy constructor.

Parameters
oElement[in] The object to copy.

Member Function Documentation

◆ Create()

tResult Create ( const tChar *&  ptr,
cDOMElement pParent,
cDOM pDocument,
const tChar pStart = nullptr 
)
protected

Parses the DOM element from the input string.

Parameters
ptr[in/out] Pointer to parser input
pParent[in] The parent element
pDocument[in] The DOM document
pStart[in] Pointer to the start of the document input string
Returns
Standard result.

◆ CreateChild() [1/2]

tResult CreateChild ( const cString strName,
cDOMElement *&  poChild 
)

Creates a new child element.

Parameters
strName[in] The name of the child.
poChild[out]
Returns
Standard result.

◆ CreateChild() [2/2]

tVoid CreateChild ( const std::list< cString > &  lstComment,
const tInt nFlag = 0 
)
protected

Parses comments from and creates pseudo DOM childs.

Parameters
lstComment[in] List of comment strings
nFlag[in] 1: before DOM child. 2: after DOM child
Returns
void

◆ Delete()

tResult Delete ( )

Removes the element from its parent element.

Returns
Standard result.

◆ EraseAttribute()

tVoid EraseAttribute ( const cString strName)

Removes an attribute.

Parameters
strName[in] The name of the attribute.
Returns
void

◆ Exists()

tBool Exists ( const cString strName) const

Checks if an attribute exists.

Parameters
strName[in] The name of the attribute.
Returns
tTrue if attribute exists, otherwise tFalse

◆ FindNode()

tResult FindNode ( const tChar strQuery,
cDOMElement *&  poElement 
)

Finds a node based on a query.

Some basic syntax:

  • queries starting with '/' are starting at the root node
  • use '*' to search all child nodes in the path
  • if you search with absolute paths, don't forget to use the root node in the path.
  • to search for certain attributes on nodes use [@property0='value'] or [@property0] to check the existence. Keep in mind that attributes search method will include parent (root) node in the elements list if search value match. In this case parent node will be the first element in the list.
  • attributes can be concatenated to make them behave like an AND: [@property0][@property1='value']
  • recursive search from root starts with '//nodes_to_search'. The whole tree is being searched.
  • recursive search from current node starts with './/nodes_to_search'. The whole subtree is being searched.
  • use '&&' or '||' to connect multiple properties logically (USE ONLY ONE OPERATOR!)

Here are some examples of search queries.

  • /root/path/to/node :absolute path to nodes
  • path/to/node :search starting on current node. Same as above, if searched in root node.
  • /root/node/* :find all children of all 'node' nodes
  • * :find all children of current node
  • /root/node[@prop='2']/* :find all children of 'node' nodes with matching attribute
  • //node :finds all 'node' nodes in the tree (recursive search)
  • .//node :recursive search starting from current node
  • //*[@prop='2'] :find all nodes in the tree with matching attributes
  • /root/path/to[@prop='2']//node :find all 'node' nodes in the subtree of the sub paths '/root/path/to'
  • child/*[@prop1='2'] :find all nodes in 'child' nodes with matching attributes
  • *[@prop1='3' && @prop2='4'] :logical AND comparison for attributes
Parameters
strQuery[in] The query string.
poElement[out] This will point to the found element.
Return values
ERR_NOT_FOUNDNo matching node found.

◆ FindNodes()

tResult FindNodes ( const tChar strQuery,
cDOMElementRefList lstElements,
tInt32  ui32Flags = 0 
)

Finds nodes based on a query.

See FindNode for the syntax.

Parameters
strQuery[in] The query string.
lstElements[out] This list will be filled with the found elements.
ui32Flags[in] Internal use
Return values
ERR_NOT_FOUNDNo matching node found.

◆ FindNodesImpl()

tResult FindNodesImpl ( const tChar strQuery,
cDOMElementRefList lstElements,
tBool bFinished,
tUInt32  ui32Flags 
)
protected

Find nodes who matches the query string.

Parameters
strQuery[in] The query string.
lstElements[out] List of DOM elements who matches the query
bFinished[out] True if find operation was successful, false otherwise
ui32Flags[in] Internal use
Returns
Standard result.

◆ Free()

tResult Free ( )

Frees all allocated resources.

Returns
Standard result.

◆ FromString()

tResult FromString ( const tChar strXML)

Creates the element from an xml string.

Parameters
strXML[in] The xml string.
Returns
Standard result.

◆ GetAttribute()

cString GetAttribute ( const cString strName,
const cString strDefault = cString() 
) const

Returns the value of an attribute.

Parameters
strName[in] The name of the attribute.
strDefault[in] A default value that is returned if the attribute does not exist.
Returns
The value of the attribute.

◆ GetAttributeBool()

tBool GetAttributeBool ( const cString strName,
tBool  bDefault = tFalse 
) const

Returns the value of an attribute interpreted as a boolean.

Parameters
strName[in] The name of the attribute.
bDefault[in] A default value that is returned if the attribute does not exist.
Returns
The value of the attribute.

◆ GetAttributeFloat64()

tFloat64 GetAttributeFloat64 ( const cString strName,
tFloat64  fDefault = 0.0 
) const

Returns the value of an attribute interpreted as a float.

Parameters
strName[in] The name of the attribute.
fDefault[in] A default value that is returned if the attribute does not exist.
Returns
The value of the attribute.

◆ GetAttributeInt()

tInt GetAttributeInt ( const cString strName,
tInt  nDefault = 0 
) const

Returns the value of an attribute interpreted as an integer.

Parameters
strName[in] The name of the attribute.
nDefault[in] A default value that is returned if the attribute does not exist.
Returns
The value of the attribute.

◆ GetAttributes() [1/2]

cDOMAttributes& GetAttributes ( )

Returns a map of alle attributes of the element.

Returns
A map of alle attributes of the element.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ GetAttributes() [2/2]

const cDOMAttributes& GetAttributes ( ) const

Returns a map of alle attributes of the element.

Returns
A map of alle attributes of the element.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ GetAttributeUInt32()

tUInt32 GetAttributeUInt32 ( const cString strName,
tUInt32  nDefault = 0 
) const

Returns the value of an attribute interpreted as an integer.

Parameters
strName[in] The name of the attribute.
nDefault[in] A default value that is returned if the attribute does not exist.
Returns
The value of the attribute.

◆ GetChild() [1/2]

cDOMElement* GetChild ( const cString strName)

Find the first child of that name of this element.

Parameters
strName[in] The name of the child element.
Returns
Pointer to the child element, or nullptr if child was not found.

◆ GetChild() [2/2]

const cDOMElement* GetChild ( const cString strName) const

Find the first child of that name of this element.

Parameters
strName[in] The name of the child element.
Returns
Pointer to the child element, or nullptr if child was not found.

◆ GetChildren() [1/2]

cDOMElementList& GetChildren ( )

Returns a list of all child elements of the element.

Returns
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ GetChildren() [2/2]

const cDOMElementList& GetChildren ( ) const

Returns a list of all child elements of the element.

Returns
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ GetData()

const cString& GetData ( ) const

Returns the data of the element.

Returns
The data.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ GetDocument() [1/2]

cDOM& GetDocument ( )

Returns the document that the element belongs to.

Returns
The document that the element belongs to.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ GetDocument() [2/2]

const cDOM& GetDocument ( ) const

Returns the document that the element belongs to.

Returns
The document that the element belongs to.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ GetName()

const cString& GetName ( ) const

Returns the name of the element.

Returns
The name of the element.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ GetParent() [1/2]

cDOMElement& GetParent ( )

Returns the elements parent element.

Returns
The elements parent element.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ GetParent() [2/2]

const cDOMElement& GetParent ( ) const

Returns the elements parent element.

Returns
The elements parent element.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ GetPath()

const cString& GetPath ( ) const

returns the current path

Return values
path
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ InsertBefore()

tResult InsertBefore ( const cDOMElement oChild,
cDOMElement pBefore 
)

Inserts an existing child element at a specified position.

Parameters
oChild[in] The child element.
pBefore[in] The child element that the new child element should be inserted before.
Returns
Standard result.

◆ InsertChild()

tResult InsertChild ( const cDOMElement oChild)

Adds an existing child element.

Parameters
oChild[in] The child element.
Returns
Standard result.

◆ MatchAttributes()

tBool MatchAttributes ( const tChar pString)
protected

Matches the attributes of the DOM child.

Parameters
pString[in] Attributes to match
Returns
tTrue if match, otherwise tFalse

◆ MatchQuery()

tBool MatchQuery ( const tChar ptr,
tUInt32 o_nOffset 
)
protected

Matches the query with the child attributes.

Parameters
ptr[in] Pointer to parser input
o_nOffset[out] Offset in input string where matching stopped
Returns
tTrue if match, otherwise tFalse

◆ operator=()

cDOMElement& operator= ( const cDOMElement oElement)

Copy assignment operator.

Parameters
oElement[in] The element to copy to.
Returns
[in] A reference to the local object.

◆ ReadAttributes()

tResult ReadAttributes ( const tChar *&  ptr,
const tChar pStart = nullptr 
)
protected

Parses the attributes from the input string.

Parameters
ptr[in/out] Pointer to parser input
pStart[in] Pointer to the start of the document input string
Returns
Standard result.

◆ ReadData()

tResult ReadData ( const tChar *&  ptr,
const tChar pStart = nullptr 
)
protected

Parses the data from the input string.

Parameters
ptr[in/out] Pointer to parser input
pStart[in] Pointer to the start of the document input string
Returns
Standard result.

◆ SetAttribute()

tVoid SetAttribute ( const cString strName,
const cString strValue 
)

Sets an attribute.

Parameters
strName[in] The attribute name.
strValue[in] The value of the attribute.
Returns
void

◆ SetData()

tVoid SetData ( const cString strData)

Sets the data of the element.

Parameters
strData[in] The new data.
Returns
void

◆ SetName()

tVoid SetName ( const cString strName)

Sets the name of the element.

Parameters
strName[in] The new name.
Returns
void

◆ ToString()

cString ToString ( ) const

Creates an xml representation of the element.

Returns
An xml representation of the element.

◆ ToStringImpl()

cString ToStringImpl ( tUInt32  ui32Flags,
tInt  nIndentLevel = 0 
) const
protected

Converts the DOM element into a textual XML like representation.

Parameters
ui32Flags[in] 0: unformated, 1:formatted
nIndentLevel[in] Defines the level of indentation
Returns
String representation