|
| | XmlHelper () |
| |
| | ~XmlHelper () |
| |
| | XmlHelper (const QString &fileName) |
| |
| | XmlHelper (QDomElement topNode) |
| | Create a XmlHelper instance with topNode as top node. More...
|
| |
| void | loadFromFile (const QString &fileName) |
| |
| QDomElement | top () const |
| |
| void | setCurrentNode (const QString &path) |
| | sets path as the current (relative) node. More...
|
| |
| void | setCurrentNode (const QDomElement &node) |
| | sets node as the current (relative) top node. More...
|
| |
| bool | isValid () const |
| | returns true if the current (relative!) node is valid (i.e. not null). More...
|
| |
| bool | hasNode (const QString &path) const |
| | returns true if path exists. More...
|
| |
| QDomElement | node (const QString &path) const |
| | retrieve node defined by path (see class description) More...
|
| |
| QString | value (const QString &path, const QString &defaultValue="") const |
| | retrieve value (as string) from node path. More...
|
| |
| bool | valueBool (const QString &path, const bool defaultValue=false) const |
| | retrieve value (as bool) from node path. More...
|
| |
| double | valueDouble (const QString &path, const double defaultValue=0.) const |
| | retrieve value (as double) from node path. More...
|
| |
| int | valueInt (const QString &path, const int defaultValue=0) const |
| | retrieve value (as int) from node path. More...
|
| |
| bool | setNodeValue (QDomElement &node, const QString &value) |
| | set value of 'node'. return true on success. More...
|
| |
| bool | setNodeValue (const QString &path, const QString &value) |
| | set value of node indicated by 'path'. return true on success. More...
|
| |
| double | paramValue (const QString ¶mName, const double defaultValue=0.) const |
| | get value of special "parameter" space More...
|
| |
| QString | paramValueString (const QString ¶mName, const QString &defaultValue="") const |
| | get value of special "parameter" space More...
|
| |
| bool | paramValueBool (const QString ¶mName, const bool &defaultValue=true) const |
| | get value of special "parameter" space More...
|
| |
| QStringList | dump (const QString &path, int levels=-1) |
| |
XmlHelper wraps a XML file and provides some convenient functions to retrieve values.
Internally XmlHelper uses a QDomDocument (the full structure is kept in memory so the size is restricted). Use node() to get a QDomElement or use value() to directly retrieve the node value. Nodes could be addressed relative to a node defined by setCurrentNode() using a ".". The notation is as follows:
- a '.' character defines a hierarchy
- [] the Nth element of the same hierarchical layer can be retrieved by [n-1] Use also the convenience functions valueBool() and valueDouble(). While all the value/node etc. functions parse the DOM tree at every call, the data accessed by paramValue() - type functions is parsed only once during startup and stored in a QVariant array. Accessible are all nodes that are children of the "<parameter>"-node.
QDomElement e,f
e = xml.node("first.second.third");
xml.setCurrentNode("first");
f = xml.node(".second.third");
e = xml.node("level1[2].level2[3].level3");
int x = xml.value(".second", "0").toInt();
if (xml.valueBool("enabled"))
...
XmlHelper xml_sec(xml.node("first.second"));
xml_sec.valueDouble("third");