lundi 20 avril 2015

No viable overloaded on XML parsing program

I have the following code which compares an XML file, then uses a map to define types of content against the names of nodes, and uses an if command to try and take actions depending on what tag is found.

#include "pugi/pugixml.hpp"

#include <iostream>
#include <string>
#include <map>

int main()
{

    const std::map<std::string, std::string> tagMap {
        {"description", "content"}, {"url", "web_address"}
    };

    pugi::xml_document doca, docb;
    std::map<std::string, pugi::xml_node> mapa, mapb;

    if (!doca.load_file("a.xml") || !docb.load_file("b.xml")) { 
        std::cout << "Can't find input files";
        return 1;
    }

    for (auto& node: doca.child("data").children("entry")) {
    const char* id = node.child_value("id");
    mapa[id] = node;
    }

    for (auto& node: docb.child("data").children("entry")) {
    const char* idcs = node.child_value("id");
        if (!mapa.erase(idcs)) {
        mapb[idcs] = node;
        }
    }

     for (auto& eb: mapb) {
         for (auto& kv : tagMap) {
         kv.first = eb.second.child_value(kv.second.c_str());
             if (kv.first == "id") {
             // Do work on id 
             }
             if (kv.first == "description") {
             // Do work on description 
             }
             if (kv.first == "url") {
             // Do work on URL data (I.e validate it)
             }
             if (kv.first == "location") {
             // Do work on location data
             }
         }
     }
}

The issue I get is when I try and compile this program I get this error:

g++ -g -Wall -std=c++11 -I include -o main src/main.cpp include/pugi/pugixml.cpp 
src/main.cpp:46:19: error: no viable overloaded '='
         kv.first = eb.second.child_value(kv.second.c_str());

This is an example input:

<data>
<entry>
<id>1</id>
<content>Test</content>
<web_address>test.com</web_address>
</entry>
</data>

Aucun commentaire:

Enregistrer un commentaire