This class can manage a very small subset of XML domain. Indeed, this is all TBT requires, to keep the code using it as simple as possible. More...
#include <xml.hh>
Inheritance diagram for xml::XML:

Public Member Functions | |
| virtual void | parse (const std::string &filename) |
| Parse an xml file. | |
| void | save () |
| Save the resulting xml file to the hard drive, replacing the file previously saved. | |
| void | setNodeAppend (bool enabled) |
| Append node, instead of replacing the first, when using setData. | |
| template<typename T> | |
| T | getData (const std::string &node_name, int index=0) const |
| Get a text value. | |
| template<typename T> | |
| T | getAttr (const std::string &node_name, const std::string &attr_name, int index=0) const |
| Get an attribute value. | |
| template<typename T> | |
| void | setData (const std::string &node_name, const T &value) |
Replace text of node node_name by value. | |
| template<typename T> | |
| void | setAttr (const std::string &node_name, const std::string &attr_name, const T &value) |
Replace an attribute of the node node_name by value. | |
| template<> | |
| void | setData (const std::string &node_name, const std::string &value) |
| template<> | |
| void | setData (const std::string &node_name, const int &value) |
| template<> | |
| void | setData (const std::string &node_name, const bool &value) |
| template<> | |
| void | setAttr (const std::string &node_name, const std::string &attr_name, const std::string &value) |
| template<> | |
| void | setAttr (const std::string &node_name, const std::string &attr_name, const int &value) |
| template<> | |
| void | setAttr (const std::string &node_name, const std::string &attr_name, const bool &value) |
Protected Member Functions | |
| virtual const char * | getExpectedRoot () const =0 |
| Root node name we expect when loading the document. | |
Protected Attributes | |
| XMLInternal * | xml_internal_ |
| std::string | filename_ |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const XML &xml) |
| Dump current xml data into ostream. Useful for debbugging. | |
This class can manage a very small subset of XML domain. Indeed, this is all TBT requires, to keep the code using it as simple as possible.
Always call parse before doing anything, not doing it will invoke strange things. Be prepared to catch XMLError, as it can be sent by approximatively all functions. Other xerces exceptions may be thrown, but consider it as a bug and report it instead of catching it.
Do not instanciate this class directly, use XML*, which have more knowledge about the document you access.
stechec/tools/xml_test directory.
| std::string xml::XML::getAttr | ( | const std::string & | node_name, | |
| const std::string & | attr_name, | |||
| int | index = 0 | |||
| ) | const |
Get an attribute value.
(ex:
<roll val="2" />
| node_name | The node to get value from. (from the exemple above, "roll"). | |
| attr_name | The attribute name to get value from. (from the example above, "val"). |
| std::string xml::XML::getData | ( | const std::string & | node_name, | |
| int | index = 0 | |||
| ) | const |
Get a text value.
(ex:
<roll>2</rool>
| node_name | The node to get text from. (from the exemple above, "roll"). |
int, bool, and | void xml::XML::parse | ( | const std::string & | filename | ) | [virtual] |
Parse an xml file.
| filename | File to parse. |
| XMLError | Thrown on any kind of error. |
Reimplemented in xml::XMLConfig, and xml::XMLFormation.
| void xml::XML::save | ( | ) |
Save the resulting xml file to the hard drive, replacing the file previously saved.
| XMLError | Thrown on any kind of error. |
| void xml::XML::setAttr | ( | const std::string & | node_name, | |
| const std::string & | attr_name, | |||
| const T & | value | |||
| ) |
Replace an attribute of the node node_name by value.
It create a new attribute if node_name is not found.
| void xml::XML::setData | ( | const std::string & | node_name, | |
| const T & | value | |||
| ) |
Replace text of node node_name by value.
It creates a new node if node_name is not found.
1.4.7