Opening and validating an XML file
The basic aim is to put repeating parts in the function, while passing as a parameter anything that's different:

if (elementMissing(source, "afcd")) {
    return;
}

if (elementMissing(source, "rteirl")) {
    return;
}

bool elementMissing(source, element) {
    if (! elementExists(source, element)) {
        ppd &lt;&lt; endl &lt;&lt; "no " &lt;&lt; element &lt;&lt; " tag";
        cRep = ppd.str();
        cSuc = false;
        return true;
    } else {
        return false;
    }
}


I'm not sure what cRep and cSuc are supposed to be doing, so I can't help you with that part.