I have a section of code that repeats many lines and I am looking to refactor this code possibly so that a function can be used instead of the same lines of code each time. Below is the section of code and the repeating code occurs in each if statementTraversal::Traversal(string source, bool isFileName) {      using namespace XML_Parser;      using std::endl;      std::ostringstream ppd;  if (isFileName)  {      string content, line;      std::ifstream file(source);      if (! file)      {          ppd << endl << error opening file  << source;          cRep = ppd.str();          cSuc = false;          return;      }      ppd << endl <<  file  << source <<  opened ;      while (file.good())      {          getline(file, line);          content += '\n';          content += line;      }      ppd << endl << file  << source <<  read ;      source = content;  }  if (! elementExists(source,afcd))  {      ppd << endl << no afcd tag;      cRep = ppd.str();      cSuc = false;      return;  }  if (! elementExists(source,rteirl))  {      ppd << endl << no rteirl tag;      cRep = ppd.str();      cSuc = false;      return;  }How would I go about making this cleaner?
Opening and validating an XML file
c++;validation;file;error handling;xml