Exemple #1
0
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,
                      const SkipError skipError)
{
    XML::Document doc(fileName, UseVirtFs_true, skipError);
    XmlNodeConstPtrConst rootNode = doc.rootNode();

    if (rootNode == nullptr || !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()))
            {
                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;
            }
            else if (xmlNameEqual(childNode, "include"))
            {
                const std::string name = XML::getProperty(
                    childNode, "name", "");
                if (!name.empty())
                {
                    readXmlStringMap(name,
                        rootName,
                        sectionName,
                        itemName,
                        attributeKeyName,
                        attributeValueName,
                        arr,
                        skipError);
                }
            }
        }
    }
}
Exemple #2
0
static void loadXmlFile(const std::string &file,
                        const std::string &name,
                        BadgesInfos &arr,
                        const SkipError skipError)
{
    readXmlStringMap(file,
        "badges",
        name,
        "badge",
        "name",
        "image",
        arr,
        skipError);
}