00001 00008 #ifndef __EASYXML_HXX 00009 #define __EASYXML_HXX 00010 00011 #include <simgear/compiler.h> 00012 #include <simgear/structure/exception.hxx> 00013 00014 #include <iostream> 00015 #include <string> 00016 #include <vector> 00017 00018 using std::istream; 00019 using std::string; 00020 using std::vector; 00021 00022 00033 class XMLAttributes 00034 { 00035 public: 00036 00040 XMLAttributes (); 00041 00042 00046 virtual ~ XMLAttributes (); 00047 00048 00054 virtual int size () const = 0; 00055 00056 00066 virtual const char * getName (int i) const = 0; 00067 00068 00078 virtual const char * getValue (int i) const = 0; 00079 00080 00092 virtual int findAttribute (const char * name) const; 00093 00094 00102 virtual bool hasAttribute (const char * name) const; 00103 00104 00115 virtual const char * getValue (const char * name) const; 00116 }; 00117 00118 00130 class XMLAttributesDefault : public XMLAttributes 00131 { 00132 public: 00133 00137 XMLAttributesDefault (); 00138 00139 00148 XMLAttributesDefault (const XMLAttributes & atts); 00149 00150 00154 virtual ~XMLAttributesDefault (); 00155 00156 00160 virtual int size () const; 00161 00162 00166 virtual const char * getName (int i) const; 00167 00168 00172 virtual const char * getValue (int i) const; 00173 00174 00183 virtual void addAttribute (const char * name, const char * value); 00184 00185 00195 virtual void setName (int i, const char * name); 00196 00197 00207 virtual void setValue (int i, const char * value); 00208 00209 00220 virtual void setValue (const char * name, const char * value); 00221 00222 private: 00223 vector<string> _atts; 00224 }; 00225 00226 00238 class XMLVisitor 00239 { 00240 public: 00241 00245 virtual ~XMLVisitor () {} 00246 00247 00258 virtual void startXML () {} 00259 00260 00275 virtual void endXML () {} 00276 00277 00296 virtual void startElement (const char * name, const XMLAttributes &atts) {} 00297 00298 00307 virtual void endElement (const char * name) {} 00308 00309 00324 virtual void data (const char * s, int length) {} 00325 00326 00341 virtual void pi (const char * target, const char * data) {} 00342 00343 00356 virtual void warning (const char * message, int line, int column) {} 00357 }; 00358 00359 00379 extern void readXML (istream &input, XMLVisitor &visitor, 00380 const string &path=""); 00381 00382 00401 extern void readXML (const string &path, XMLVisitor &visitor); 00402 00403 00423 extern void readXML (const char *buf, const int size, XMLVisitor &visitor); 00424 00425 00426 #endif // __EASYXML_HXX 00427