It is necessary from the file (here is its text) to parse just what is between the <keyMaterial> </keyMaterial> . How can this be implemented in C ++?

// UPD. I solved the problem in the following way:

 // ConsoleApplication11.cpp: определяет точку входа для консольного приложения. // #include <iostream> #include <string> #include <fstream> #include <iterator> int main() { std::ifstream ifs("{1AC815AC-7555-48FB-B768-9E171453FE23}.xml"); { std::string s; s.assign((std::istreambuf_iterator<char>(ifs.rdbuf())), std::istreambuf_iterator<char>()); size_t begin = s.find("<keyMaterial>") + 13; size_t end = s.find("</keyMaterial>"); s = s.substr(begin, end - begin); std::cout << s; ifs.close(); } system("pause"); return 0; } 
  • five
    Drive in Google "C ++ XML parser" and choose the one that you like best. - PinkTux
  • What do you mean by "sparse" in this case? there is just a long string - what do you want to get? - Harry
  • @Harry need everything that is in the tag (01000000D ..... E426F). - Danij
  • Once decided - post the answer, maybe someone else will come in handy. - user227465
  • If possible, publish the solution found in response to your question . I am sure it will help many of your colleagues in the future. - Nicolas Chabanovsky

1 answer 1

As an option:

 #include <iostream> #include <fstream> #include <regex> int main() { try { std::ifstream ifs("{1AC815AC-7555-48FB-B768-9E171453FE23}.xml"); std::stringstream sstream; sstream << ifs.rdbuf(); std::string str = sstream.str(); std::regex rx("(?:.|\\n|\\r)*?<keyMaterial>(.+?)</keyMaterial>(?:.|\\n\\r)*"); std::smatch match; if(!(std::regex_search(str, match, rx) && match.size()==2)) throw std::runtime_error("Substring not found!"); std::cout << match[1] << std::endl; } catch(std::runtime_error &e) { std::cout << "Error: " << e.what() << std::endl; } catch(...) { std::cout << "Some error!" << std::endl; } return 0; }