XML parsing program in C++ This is my code which works and compiles but I feel it may be non-optimal, especially the tag mapping and  use of the if command.

It reads two .xml files and finds what has been added or deleted on the new file. For new items it uses a map to link a tag name to a category of data (content tag is a description for example). This is important since different files have different naming conventions on the tags.

Finally, it does work on the data depending on its category (coming soon) and prints it.

#include "pugi/pugixml.hpp"

#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;map&gt;

int main()
{

    std::string var;

    const std::map&lt;std::string, std::string&gt; tagMap {
        {"id", "id"}, {"description", "content"}, {"url", "web_address"}
    };

    pugi::xml_document doca, docb;
    std::map&lt;std::string, pugi::xml_node&gt; mapa, mapb;

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

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

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

     for (auto&amp; eb: mapb) {
        // Loop the tagMap, and try and associate the tag name to the content
         for (auto&amp; kv : tagMap) {
             if (kv.first == "id") {
             std::string var = eb.second.child_value(kv.second.c_str());
             // Do work on returned value of id tag in the future (I.e validation)
             std::cout &lt;&lt; var &lt;&lt; endl;
             }
             if (kv.first == "description") {
             std::string var = eb.second.child_value(kv.second.c_str());
             // Do work on returned value of content tag in the future
             std::cout &lt;&lt; var &lt;&lt; endl;
             }
             if (kv.first == "url") {
             std::string var = eb.second.child_value(kv.second.c_str());
             // Do work on returned value of web_address tag in the future
             std::cout &lt;&lt; var &lt;&lt; endl;
             }
         }
     }
}
I will only comment about the following not-fully-implemented part.

 for (auto&amp; kv : tagMap) {
     if (kv.first == "id") {
     std::string var = eb.second.child_value(kv.second.c_str());
     // Do work on returned value of id tag in the future (I.e validation)
     std::cout &lt;&lt; var &lt;&lt; endl;
     }
     if (kv.first == "description") {
     std::string var = eb.second.child_value(kv.second.c_str());
     // Do work on returned value of content tag in the future
     std::cout &lt;&lt; var &lt;&lt; endl;
     }
     if (kv.first == "url") {
     std::string var = eb.second.child_value(kv.second.c_str());
     // Do work on returned value of web_address tag in the future
     std::cout &lt;&lt; var &lt;&lt; endl;
     }
 }


Even without much code filling the blanks, it seems that you want to have some associative tag =&gt; function data. In which case, you could create an std::unordered_map with strings as keys and associating function pointers to them, generated from captureless lambdas. A small example:

std::unordered_map&lt;std::string, void(*)(const std::string&amp;)&gt; tasks = {
    { "id", [](const std::string&amp; val) {
        // Do work on returned value of id tag
    }},
    { "description", [](const std::string&amp; val) {
        // Do work on returned value of content tag
    }},
    { "url", [](const std::string&amp; val) {
        // Do work on returned value of web_address tag
    }}
};

for (auto&amp; kv: tagMap) {
    auto it = tasks.find(kv.first);
    if (it != tasks.end()) {
        it-&gt;second(eb.second.child_value(kv.second.c_str()));
    }
}


That way, your code is easy to extend to other tags by representing tasks associated to tags as data and storing them into a map. Now, it will only work if you don't need captures, otherwise, you may have to use std::function or some more heavyweight mechanism instead of a big chain of if.