Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. /*
  2. #include <tinyxml.h>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. void get_person(string& find)
  8. {
  9. TiXmlDocument doc("XMLFile1.xml");
  10. if (!doc.LoadFile())
  11. return;
  12. TiXmlElement* element = doc.FirstChildElement("AddressBook");
  13. element = element->FirstChildElement("Contact");
  14. int answer = 0;
  15.  
  16. TiXmlDocument ans;
  17.  
  18. while (element != NULL) {
  19. if (string(element->FirstChildElement("FirstName")->GetText()) == find) {
  20. answer++;
  21. ans.LinkEndChild(new TiXmlElement(*element));
  22. }
  23. element = element->NextSiblingElement("Contact");
  24.  
  25. }
  26.  
  27. ans.SaveFile("XMLFile2.xml");
  28. cout << answer;
  29. }
  30.  
  31. int main()
  32. {
  33. string have = "Ivan";
  34. get_person(have);
  35. return 0;
  36. }
  37. */
  38.  
  39.  
  40.  
  41.  
  42. <AddressBook>
  43. <Contact>
  44. <FirstName>Ivan</FirstName>
  45. <LastName>Petrov</LastName>
  46. <Phone>
  47. <phonenumber>123456</phonenumber>
  48. <accountindex>1</accountindex>
  49. <downloaded>1</downloaded>
  50. </Phone>
  51. <Groups>
  52. <groupid>2</groupid>
  53. </Groups>
  54. </Contact>
  55. <Contact>
  56. <FirstName>Petr</FirstName>
  57. <LastName>Sidorov</LastName>
  58. <Phone>
  59. <phonenumber>456789</phonenumber>
  60. <accountindex>1</accountindex>
  61. <downloaded>1</downloaded>
  62. </Phone>
  63. <Groups>
  64. <groupid>2</groupid>
  65. </Groups>
  66. </Contact>
  67. <Contact>
  68. <FirstName>Petr</FirstName>
  69. <LastName>Sidorov</LastName>
  70. <Phone>
  71. <phonenumber>456789</phonenumber>
  72. <accountindex>1</accountindex>
  73. <downloaded>1</downloaded>
  74. </Phone>
  75. <Groups>
  76. <groupid>2</groupid>
  77. </Groups>
  78. </Contact>
  79. </AddressBook>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement