mercredi 22 avril 2015

Compare XML program compiles but no output or error

#include "pugi/pugixml.hpp"

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

using namespace std;

int main()
{
    pugi::xml_document doca, docb;
    std::map<std::string, pugi::xml_node> mapa, mapb;
    std::map<int, std::string> tagMap {make_pair(1, "data"), make_pair(2, "item"), make_pair(3, "id"), make_pair(4, "content")};

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

    for (const auto& node: doca.child(tagMap[1].c_str()).children(tagMap[2].c_str())) {
            const auto& id = node.child_value(tagMap[3].c_str());
            mapa[id] = node;
    }

    for (const auto& node: doca.child(tagMap[1].c_str()).children(tagMap[2].c_str())) {
            const auto& idcs = node.child_value(tagMap[3].c_str());
            if (!mapa.erase(idcs)) {
                mapb[idcs] = node;
            }
    }

    for (auto& ea: mapa) {
        std::cout << "Removed:" << std::endl;
        ea.second.print(std::cout);
    }

    for (auto& eb: mapb) {
        std::cout << "Added:" << std::endl;
        eb.second.print(std::cout);
    }
}

It should spit out the differences in the two XML files, but instead it doesn't print anything at all.

a.xml

<data>
<item>
<id>1</id>
<content>Test</content>
</item>
<item>
<id>2</id>
<content>Testing</content>
</item>
</data>

b.xml

<data>
<item>
<id>2</id>
<content>Testing</content>
</item>
<item>
<id>4</id>
<content>Testing again</content>
</item>
</data>

I've had issues before but at least I get compile errors, but with this it seems like everything is fine, but it just doesn't work. What can I do to diagnose the problem?

Aucun commentaire:

Enregistrer un commentaire