diff options
-rw-r--r-- | src/utils/xmlutils.cpp | 39 | ||||
-rw-r--r-- | src/utils/xmlutils.h | 9 |
2 files changed, 48 insertions, 0 deletions
diff --git a/src/utils/xmlutils.cpp b/src/utils/xmlutils.cpp index 232ec92b1..937695d41 100644 --- a/src/utils/xmlutils.cpp +++ b/src/utils/xmlutils.cpp @@ -61,3 +61,42 @@ void readXmlIntVector(const std::string &fileName, } } } + +void readXmlStringMap(const std::string &fileName, + const std::string &rootName, + const std::string §ionName, + const std::string &itemName, + const std::string &attributeKeyName, + const std::string &attributeValueName, + std::map<std::string, std::string> &arr) +{ + arr.clear(); + XML::Document doc(fileName, UseResman_true, SkipError_false); + const XmlNodePtrConst rootNode = doc.rootNode(); + + if (!rootNode || !xmlNameEqual(rootNode, rootName.c_str())) + { + logger->log("Error while loading %s!", fileName.c_str()); + return; + } + + for_each_xml_child_node(sectionNode, rootNode) + { + if (!xmlNameEqual(sectionNode, sectionName.c_str())) + continue; + for_each_xml_child_node(childNode, sectionNode) + { + if (!xmlNameEqual(childNode, itemName.c_str())) + continue; + + const std::string key = XML::getProperty(childNode, + attributeKeyName.c_str(), ""); + if (key.empty()) + continue; + const std::string val = XML::getProperty(childNode, + attributeValueName.c_str(), ""); + + arr[key] = val; + } + } +} diff --git a/src/utils/xmlutils.h b/src/utils/xmlutils.h index 9715b005a..e5ac40f5c 100644 --- a/src/utils/xmlutils.h +++ b/src/utils/xmlutils.h @@ -22,6 +22,7 @@ #define UTILS_XMLUTILS_H #include <string> +#include <map> #include <vector> void readXmlIntVector(const std::string &fileName, @@ -31,4 +32,12 @@ void readXmlIntVector(const std::string &fileName, const std::string &attributeName, std::vector<int> &arr); +void readXmlStringMap(const std::string &fileName, + const std::string &rootName, + const std::string §ionName, + const std::string &itemName, + const std::string &attributeKeyName, + const std::string &attributeValueName, + std::map<std::string, std::string> &arr); + #endif // UTILS_XMLUTILS_H |