fork download
  1. void TTT(){
  2.  
  3. tinyxml2::XMLDocument docXml;
  4. XMLError errXml = docXml.LoadFile("../oldData.xml");
  5. if (XML_SUCCESS == errXml){
  6. XMLElement* elmtRoot = docXml.RootElement();
  7. XMLElement *elmtStaff = elmtRoot->FirstChildElement("Staff");
  8. XMLElement *elmtName = elmtStaff->FirstChildElement("Name");
  9. if (elmtName)
  10. {
  11. const char* pContent = elmtName->GetText();
  12. printf( "%s", pContent);
  13. }
  14.  
  15. XMLElement *elmtID = elmtName->NextSiblingElement("ID");
  16. if (elmtID)
  17. {
  18. const char* pContent= elmtID->GetText();
  19. printf( "%s", pContent);
  20. }
  21. XMLElement *elmtDepartment = elmtID->NextSiblingElement("Department");
  22. if (elmtDepartment)
  23. {
  24. const char* pContent= elmtDepartment->GetText();
  25. printf( "%s", pContent);
  26. }
  27. XMLElement *elmtSalary = elmtDepartment->NextSiblingElement("Salary");
  28. if (elmtSalary)
  29. {
  30. const char* pContent= elmtSalary->GetText();
  31. printf( "%s", pContent);
  32. }
  33. XMLElement *elmtAge = elmtName->NextSiblingElement();
  34. if (elmtAge)
  35. {
  36. const char* pContent= elmtAge->GetText();
  37. printf( "%s", pContent);
  38. }
  39. }
  40. }
  41.  
  42. int main(int argc, char **argv)
  43. {
  44.  
  45. TTT();
  46.  
  47. return 0;
  48. }
  49. //The following txt is what the program reads.
  50. /*
  51.  
  52.  
  53. <Staff>
  54.  <Name> David Lee </Name>
  55.  <ID> 1234567 </ID>
  56.  <age> 38 </age>
  57.  <Department> CS </Department>
  58.  <Salary> 100000</Salary>
  59. </Staff>
  60. <Staff>
  61.  <Name> Jeff Wu </Name >
  62.  <ID> 1234568 </ID>
  63.  <age> 50 </age>
  64.  <Department> EE </Department>
  65.  <Salary> 200000</Salary>
  66. </Staff>
  67. <Staff>
  68.  <Name> Nancy Wang </Name >
  69.  <ID> 1234569 </ID>
  70.  <age> 43 </age>
  71.  <Department> CS </Department>
  72.  <Salary> 160000</Salary>
  73. </Staff>*/
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘void TTT()’:
prog.cpp:3:5: error: ‘tinyxml2’ has not been declared
     tinyxml2::XMLDocument docXml;
     ^~~~~~~~
prog.cpp:4:5: error: ‘XMLError’ was not declared in this scope
     XMLError errXml = docXml.LoadFile("../oldData.xml");
     ^~~~~~~~
prog.cpp:5:9: error: ‘XML_SUCCESS’ was not declared in this scope
     if (XML_SUCCESS == errXml){
         ^~~~~~~~~~~
prog.cpp:5:24: error: ‘errXml’ was not declared in this scope
     if (XML_SUCCESS == errXml){
                        ^~~~~~
prog.cpp:6:9: error: ‘XMLElement’ was not declared in this scope
         XMLElement* elmtRoot = docXml.RootElement();
         ^~~~~~~~~~
prog.cpp:6:21: error: ‘elmtRoot’ was not declared in this scope
         XMLElement* elmtRoot = docXml.RootElement();
                     ^~~~~~~~
prog.cpp:6:32: error: ‘docXml’ was not declared in this scope
         XMLElement* elmtRoot = docXml.RootElement();
                                ^~~~~~
prog.cpp:7:21: error: ‘elmtStaff’ was not declared in this scope
         XMLElement *elmtStaff = elmtRoot->FirstChildElement("Staff");
                     ^~~~~~~~~
prog.cpp:8:21: error: ‘elmtName’ was not declared in this scope
         XMLElement *elmtName = elmtStaff->FirstChildElement("Name");
                     ^~~~~~~~
prog.cpp:12:35: error: ‘printf’ was not declared in this scope
             printf( "%s", pContent);
                                   ^
prog.cpp:15:21: error: ‘elmtID’ was not declared in this scope
         XMLElement *elmtID = elmtName->NextSiblingElement("ID");
                     ^~~~~~
prog.cpp:19:35: error: ‘printf’ was not declared in this scope
             printf( "%s", pContent);
                                   ^
prog.cpp:21:21: error: ‘elmtDepartment’ was not declared in this scope
         XMLElement *elmtDepartment = elmtID->NextSiblingElement("Department");
                     ^~~~~~~~~~~~~~
prog.cpp:25:35: error: ‘printf’ was not declared in this scope
             printf( "%s", pContent);
                                   ^
prog.cpp:27:21: error: ‘elmtSalary’ was not declared in this scope
         XMLElement *elmtSalary = elmtDepartment->NextSiblingElement("Salary");
                     ^~~~~~~~~~
prog.cpp:31:35: error: ‘printf’ was not declared in this scope
             printf( "%s", pContent);
                                   ^
prog.cpp:33:21: error: ‘elmtAge’ was not declared in this scope
         XMLElement *elmtAge = elmtName->NextSiblingElement();
                     ^~~~~~~
prog.cpp:37:35: error: ‘printf’ was not declared in this scope
             printf( "%s", pContent);
                                   ^
stdout
Standard output is empty