From dc6afb20dd1af4e9e3a8ff4d3f2f3fcf5cd87734 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 29 Jul 2015 02:03:39 +0300 Subject: Add function for load xml data to std::map with strings. --- src/utils/xmlutils.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/utils/xmlutils.cpp') 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 &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; + } + } +} -- cgit v1.2.3-70-g09d2