GEAR  1.9.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends Pages
mergeXML.cc
1 #include "gearxml/tinyxml.h"
2 #include "gearxml/MergeXML.h"
3 #include "gear/GEAR.h"
4 
5 
18 int main( int argc, char *argv[] ) {
19 
20  try{
21 
22  if( argc < 4 ) {
23 
24  std::cout << std::endl
25  << " Program to merge two xml files. This can be used if a gear xml" << std::endl
26  << " (that has been automatically created with MokkaGear) is lacking" << std::endl
27  << " some information. XML Elements that are present in only one of the input" << std::endl
28  << " files will be merged into the target file. In case the same element" << std::endl
29  << " exists in either input file the attribute values from the primary file" << std::endl
30  << " are taken." << std::endl
31  << std::endl
32  << "usage: " << std::endl
33  << " mergeXML <secondary> <primary> <target> " << std::endl
34  << " <secondary> filename for base-file that will be overwritten" << std::endl
35  << " <primary> filename for file that overrules secondary file" << std::endl
36  << " <target> filename for output file " << std::endl
37  << std::endl ;
38  exit(1) ;
39  }
40 
41 
42  std::string fileName1 = argv[1] ;
43  std::string fileName2 = argv[2] ;
44  std::string fileNameNew = argv[3] ;
45 
46  gear::MergeXML mergeXML ;
47 
48  if ( mergeXML.setFile1 (fileName1) ) {
49  std::cout << "secondary : ok" << std::endl ;
50  }
51  else {
52  std::cout << "secondary : error reading file " << fileName1 << std::endl ;
53  exit (2) ;
54  }
55 
56  if ( mergeXML.setFile2 (fileName2) ) {
57  std::cout << "primary: ok" << std::endl ;
58  }
59  else {
60  std::cout << "primary: error reading file " << fileName2 << std::endl ;
61  exit (2) ;
62  }
63 
64  if ( mergeXML.mergeFiles(fileNameNew) ) {
65  std::cout << "target : ok" << std::endl ;
66  }
67  else {
68  std::cout << "target: error merging files in " << fileNameNew << std::endl ;
69  exit(1) ;
70  }
71 
72  return 0;
73 
74  }
75  catch( gear::Exception& e) {
76  std::cout << " An Exception occured : " << e.what() << std::endl ;
77  }
78 
79 }
80 
81 
bool mergeFiles(const std::string &fileName)
merges files
Definition: MergeXML.cc:36
Base exception class for GEAR - all other exceptions extend this.
Definition: GEAR.h:41
class to merge two xml files.
Definition: MergeXML.h:18
bool setFile1(const std::string &fileName)
Sets first filename returns true if file can be read.
Definition: MergeXML.cc:9
bool setFile2(const std::string &fileName)
Sets second filename returns true if file can be read.
Definition: MergeXML.cc:17