summaryrefslogtreecommitdiff
path: root/src/utils/xmlutils.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-07-29 02:03:39 +0300
committerAndrei Karas <akaras@inbox.ru>2015-07-29 02:03:39 +0300
commitdc6afb20dd1af4e9e3a8ff4d3f2f3fcf5cd87734 (patch)
tree8d944bed5a0e296b544440e26781931e20d66879 /src/utils/xmlutils.cpp
parentf83dce6cb491c66721ff319ab90d9aad23a349eb (diff)
downloadmv-dc6afb20dd1af4e9e3a8ff4d3f2f3fcf5cd87734.tar.gz
mv-dc6afb20dd1af4e9e3a8ff4d3f2f3fcf5cd87734.tar.bz2
mv-dc6afb20dd1af4e9e3a8ff4d3f2f3fcf5cd87734.tar.xz
mv-dc6afb20dd1af4e9e3a8ff4d3f2f3fcf5cd87734.zip
Add function for load xml data to std::map with strings.
Diffstat (limited to 'src/utils/xmlutils.cpp')
-rw-r--r--src/utils/xmlutils.cpp39
1 files changed, 39 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 &sectionName,
+ 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;
+ }
+ }
+}