]> git.mxchange.org Git - simgear.git/blob - simgear/xml/testEasyXML.cxx
Reduce compiler.h to almost nothing (but it's worth keeping around I think, for
[simgear.git] / simgear / xml / testEasyXML.cxx
1 #include <string>
2 #include <iostream>
3 #include <fstream>
4 #include "easyxml.hxx"
5
6 using std::string;
7 using std::ifstream;
8 using std::cout;
9 using std::cerr;
10 using std::endl;
11
12 class MyVisitor : public XMLVisitor
13 {
14 public:
15   virtual void startXML () {
16     cout << "Start XML" << endl;
17   }
18   virtual void endXML () {
19     cout << "End XML" << endl;
20   }
21   virtual void startElement (const char * name, const XMLAttributes &atts) {
22     cout << "Start element " << name << endl;
23     for (int i = 0; i < atts.size(); i++)
24       cout << "  " << atts.getName(i) << '=' << atts.getValue(i) << endl;
25   }
26   virtual void endElement (const char * name) {
27     cout << "End element " << name << endl;
28   }
29   virtual void data (const char * s, int len) {
30     cout << "Character data " << string(s,len) << endl;
31   }
32   virtual void pi (const char * target, const char * data) {
33     cout << "Processing instruction " << target << ' ' << data << endl;
34   }
35   virtual void warning (const char * message, int line, int column) {
36     cout << "Warning: " << message << " (" << line << ',' << column << ')'
37          << endl;
38   }
39   virtual void error (const char * message, int line, int column) {
40     cout << "Error: " << message << " (" << line << ',' << column << ')'
41          << endl;
42   }
43 };
44
45 int main (int ac, const char ** av)
46 {
47   MyVisitor visitor;
48
49   for (int i = 1; i < ac; i++) {
50     ifstream input(av[i]);
51     cout << "Reading " << av[i] << endl;
52     try {
53       readXML(input, visitor);
54
55     } catch (const sg_exception& e) {
56       cerr << "Error: file '" << av[i] << "' " << e.getFormattedMessage() << endl;
57       return -1;
58
59     } catch (...) {
60       cerr << "Error reading from " << av[i] << endl;
61       return -1;
62     }
63   }
64   return 0;
65 }