| CRM64Pro GDK v0.17.0 A free cross-platform game development kit built on top of SDL 3.0

Loading...
Searching...
No Matches
CRM64Pro::XML
Core modules » XML

XML Object class. More...

## Detailed Description

XML Object class.

## Public Member Functions
bool | info (Sint32 iMode=0) override
| Request XML object information.
const string & | getName () const override
| Get the name.
Uint32 | getID () const override
| Get the ID.
bool | nodePointTo (Sint32 iParam, const char *szNodes,...)
| Point to a node using a va_list of node names.
bool | nodeFirst ()
| Point to the first XML node (the root node).
bool | nodeNext ()
| Point to the next node (from current pointed node).
bool | nodePrev ()
| Point to the previous node (from current pointed node).
bool | nodeParent ()
| Point to the parent node (from current pointed node).
bool | nodeChild ()
| Point to the first child node (from current pointed node).
bool | nodeStore ()
| Store node pointer position.
bool | nodeRestore ()
| Restore node pointer position.
bool | nodeRemove ()
| Remove pointed node and all its subnodes and attributes.
bool | nodeCreate (const string &sNode)
| Create a new node inside the pointed node and point to it.
bool | nodeRename (const string &sNode)
| Rename pointed node.
bool | nodeGetName (string &sNode)
| Get the name of pointed node.
bool | hasAttribute (const string &sAttr) const
| Check if an attribute exists inside the pointed node.
bool | setAttributeString (const string &sAttr, const string &sValue)
| Set an attribute inside pointed node with a string value.
bool | setAttributeInt (const string &sAttr, Sint32 iValue)
| Set an attribute inside pointed node with an integer value.
bool | setAttributeUint (const string &sAttr, Uint32 iValue)
| Set an attribute inside pointed node with an unsigned integer value.
bool | setAttributeFloat (const string &sAttr, float fValue)
| Set an attribute inside pointed node with a float value.
bool | setAttributeBool (const string &sAttr, bool bValue)
| Set an attribute inside pointed node with a boolean value.
string | getAttributeString (const string &sAttr, const string &sDefault="") const
| Get the string value of an attribute inside the pointed node.
Sint32 | getAttributeInt (const string &sAttr, Sint32 iDefault=0) const
| Get the integer (signed) value of an attribute inside the pointed node.
Uint32 | getAttributeUint (const string &sAttr, Uint32 iDefault=0) const
| Get the integer (unsigned) value of an attribute inside the pointed node.
float | getAttributeFloat (const string &sAttr, float fDefault=0.0f) const
| Get the float value of an attribute inside the pointed node.
bool | getAttributeBool (const string &sAttr, bool bDefault=false) const
| Get the boolean value of an attribute inside the pointed node.
bool | removeAttribute (const string &sAttr)
| Remove an attribute and its value inside the pointed node.
bool | setText (const string &sText)
| Set a text inside the pointed node.
bool | getText (string &sText)
| Get the text contained in the pointed node.
bool | removeText ()
| Remove the text inside the pointed node.
bool | setComment (const string &sComment)
| Set a comment text inside the pointed node.
bool | getComment (string &sComment)
| Get the comment text contained in the pointed node.
bool | removeComment ()
| Remove the comment text inside the pointed node.
Sint32 | saveToFile (const string &sFile)
| Export the XML to an external file.
Sint32 | save (const string &sCDCFile, const string &sResourceName="")
| Save the XML into a CDC file.
Sint32 | save (const Sint32 idCDC, const string &sResourceName="")
| Save the XML in to a CDC file.

## Member Function Documentation

## ◆ info()

bool CRM64Pro::XML::info | ( | Sint32 | iMode = 0 | ) |
| override

Request XML object information.

Writes information to the default log.

Parameters

  iMode | unused for the time being.

Returns
  true on success or false on failure.

## ◆ getName()

const string & CRM64Pro::XML::getName | ( |  | ) | const
| override

Get the name.

Returns
  The object name.

## ◆ getID()

Uint32 CRM64Pro::XML::getID | ( |  | ) | const
| override

Get the ID.

Returns
  Object ID.

## ◆ nodePointTo()

bool CRM64Pro::XML::nodePointTo | ( | Sint32 | iParam,
|  | const char * | szNodes,
|  |  | ... )

Point to a node using a va_list of node names.

Parameters

  iParam | number of arguments.
  szNodes | variable arguments list of strings (char*) with the node names.

Returns
  true on success or false on failure.

## ◆ nodeFirst()

bool CRM64Pro::XML::nodeFirst | ( |  | ) |

Point to the first XML node (the root node).

Returns
  true on success (found root) or false on failure (empty document).

## ◆ nodeNext()

bool CRM64Pro::XML::nodeNext | ( |  | ) |

Point to the next node (from current pointed node).

Returns
  true on success (moved to next node) or false on failure (no more nodes or current node is null).

## ◆ nodePrev()

bool CRM64Pro::XML::nodePrev | ( |  | ) |

Point to the previous node (from current pointed node).

Returns
  true on success (moved to previous node) or false on failure (no previous node or current node is null).

## ◆ nodeParent()

bool CRM64Pro::XML::nodeParent | ( |  | ) |

Point to the parent node (from current pointed node).

Returns
  true on success (moved to parent node) or false on failure (no parent node or current node is null).

## ◆ nodeChild()

bool CRM64Pro::XML::nodeChild | ( |  | ) |

Point to the first child node (from current pointed node).

Returns
  true on success (moved to child node) or false on failure (no child nodes or current node is null).

## ◆ nodeStore()

bool CRM64Pro::XML::nodeStore | ( |  | ) |

Store node pointer position.

Each XML has a single slot, so it keeps only the most recently stored position.

Returns
  true on success or false on failure.

## ◆ nodeRestore()

bool CRM64Pro::XML::nodeRestore | ( |  | ) |

Restore node pointer position.

Each XML has a single slot, so it restores the position saved by the last nodeStore() call.

Returns
  true on success or false on failure.

## ◆ nodeRemove()

bool CRM64Pro::XML::nodeRemove | ( |  | ) |

Remove pointed node and all its subnodes and attributes.

Returns
  true on success or false on failure.

## ◆ nodeCreate()

bool CRM64Pro::XML::nodeCreate | ( | const string & | sNode | ) |

Create a new node inside the pointed node and point to it.

Parameters

  sNode | string containing the node name.

Returns
  true on success or false on failure.

## ◆ nodeRename()

bool CRM64Pro::XML::nodeRename | ( | const string & | sNode | ) |

Rename pointed node.

Parameters

  sNode | string containing the node name.

Returns
  true on success or false on failure.

## ◆ nodeGetName()

bool CRM64Pro::XML::nodeGetName | ( | string & | sNode | ) |

Get the name of pointed node.

Parameters

  sNode | a string variable. Will not be modified when there is not a valid pointed node.

Returns
  true on success or false on failure.

## ◆ hasAttribute()

bool CRM64Pro::XML::hasAttribute | ( | const string & | sAttr | ) | const

Check if an attribute exists inside the pointed node.

Parameters

  sAttr | attribute name string.

Returns
  true if it exists, false otherwise.

## ◆ setAttributeString()

bool CRM64Pro::XML::setAttributeString | ( | const string & | sAttr,
|  | const string & | sValue )

Set an attribute inside pointed node with a string value.

Parameters

  sAttr | attribute name string.
  sValue | string value.

Returns
  true on success or false on failure.

## ◆ setAttributeInt()

bool CRM64Pro::XML::setAttributeInt | ( | const string & | sAttr,
|  | Sint32 | iValue )

Set an attribute inside pointed node with an integer value.

Parameters

  sAttr | attribute name string.
  iValue | integer value.

Returns
  true on success or false on failure.

## ◆ setAttributeUint()

bool CRM64Pro::XML::setAttributeUint | ( | const string & | sAttr,
|  | Uint32 | iValue )

Set an attribute inside pointed node with an unsigned integer value.

Parameters

  sAttr | attribute name string.
  iValue | unsigned integer value.

Returns
  true on success or false on failure.

## ◆ setAttributeFloat()

bool CRM64Pro::XML::setAttributeFloat | ( | const string & | sAttr,
|  | float | fValue )

Set an attribute inside pointed node with a float value.

Parameters

  sAttr | attribute name string.
  fValue | float value.

Returns
  true on success or false on failure.

## ◆ setAttributeBool()

bool CRM64Pro::XML::setAttributeBool | ( | const string & | sAttr,
|  | bool | bValue )

Set an attribute inside pointed node with a boolean value.

Parameters

  sAttr | attribute name string.
  bValue | boolean value.

Returns
  true on success or false on failure.

## ◆ getAttributeString()

string CRM64Pro::XML::getAttributeString | ( | const string & | sAttr,
|  | const string & | sDefault = "" ) const

Get the string value of an attribute inside the pointed node.

Parameters

  sAttr | attribute name string.
  sDefault | value to return if attribute does not exist.

Returns
  string with the attribute value or sDefault.

## ◆ getAttributeInt()

Sint32 CRM64Pro::XML::getAttributeInt | ( | const string & | sAttr,
|  | Sint32 | iDefault = 0 ) const

Get the integer (signed) value of an attribute inside the pointed node.

Parameters

  sAttr | attribute name string.
  iDefault | value to return if attribute does not exist.

Returns
  attribute value or iDefault.

## ◆ getAttributeUint()

Uint32 CRM64Pro::XML::getAttributeUint | ( | const string & | sAttr,
|  | Uint32 | iDefault = 0 ) const

Get the integer (unsigned) value of an attribute inside the pointed node.

Parameters

  sAttr | attribute name string.
  iDefault | value to return if attribute does not exist.

Returns
  attribute value or iDefault.

## ◆ getAttributeFloat()

float CRM64Pro::XML::getAttributeFloat | ( | const string & | sAttr,
|  | float | fDefault = 0.0f ) const

Get the float value of an attribute inside the pointed node.

Parameters

  sAttr | attribute name string.
  fDefault | value to return if attribute does not exist.

Returns
  attribute value or fDefault.

## ◆ getAttributeBool()

bool CRM64Pro::XML::getAttributeBool | ( | const string & | sAttr,
|  | bool | bDefault = false ) const

Get the boolean value of an attribute inside the pointed node.

Parameters

  sAttr | attribute name string.
  bDefault | value to return if attribute does not exist.

Returns
  attribute value or bDefault.

## ◆ removeAttribute()

bool CRM64Pro::XML::removeAttribute | ( | const string & | sAttr | ) |

Remove an attribute and its value inside the pointed node.

Parameters

  sAttr | attribute name string.

Returns
  true on success or false on failure.

## ◆ setText()

bool CRM64Pro::XML::setText | ( | const string & | sText | ) |

Set a text inside the pointed node.

If there is not any text, it will be created. Otherwise, the text will be appended to the exiting one.

Parameters

  sText | text string.

Returns
  true on success or false on failure.>

## ◆ getText()

bool CRM64Pro::XML::getText | ( | string & | sText | ) |

Get the text contained in the pointed node.

Parameters

  sText | a string variable. Not modified if no text exists.

Returns
  true on success or false on failure.

## ◆ removeText()

bool CRM64Pro::XML::removeText | ( |  | ) |

Remove the text inside the pointed node.

Returns
  true on success or false on failure.

## ◆ setComment()

bool CRM64Pro::XML::setComment | ( | const string & | sComment | ) |

Set a comment text inside the pointed node.

If a comment already exists, it will be pushed down and the new comment will be the first one.

Parameters

  sComment | comment text string.

Returns
  true on success or false on failure.

## ◆ getComment()

bool CRM64Pro::XML::getComment | ( | string & | sComment | ) |

Get the comment text contained in the pointed node.

Parameters

  sComment | a string variable. Not modified if no comment exists.

Returns
  true on success or false on failure.

Note
  Only gets the first comment text block found.

## ◆ removeComment()

bool CRM64Pro::XML::removeComment | ( |  | ) |

Remove the comment text inside the pointed node.

Returns
  true on success or false on failure.

Note
  Only removes the first comment text block found. Call repeatedly until a negative error code to remove all comments.

## ◆ saveToFile()

Sint32 CRM64Pro::XML::saveToFile | ( | const string & | sFile | ) |

Export the XML to an external file.

Parameters

  sFile | string containing [directory]+filename+[extension]. Ideally should have the .xml extension. If the file exists, it will be overwritten. Directory separators '\' and '/' are supported.

Returns
  0 or greater on success or a negative error code on failure.

## ◆ save() [1/2]

Sint32 CRM64Pro::XML::save | ( | const string & | sCDCFile,
|  | const string & | sResourceName = "" )

Save the XML into a CDC file.

If the XML already exists on the CDC, it will be overwritten.

Parameters

  sCDCFile | string containing [directory]+filename+[extension]. Directory separators '\' and '/' are supported.
  sResourceName | Optional resource name to use in the CDC. If empty (default), uses the XML object's internal name.

Returns
  greater than 0 on success (the size of this block on the CDC) or a negative error code on failure.

Note
  If the CDC file is secured, this call will fail. Open the CDC first using ArchiveMgr::open() and use XML::save() with the CDC id instead.

## ◆ save() [2/2]

Sint32 CRM64Pro::XML::save | ( | const Sint32 | idCDC,
|  | const string & | sResourceName = "" )

Save the XML in to a CDC file.

If the XML already exists on the CDC, it will be overwritten.

Parameters

  idCDC | CDC id.
  sResourceName | Optional resource name to use in the CDC. If empty (default), uses the XML object's internal name.

Returns
  greater than 0 on success or a negative error code on failure.