00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef XML_H
00025 #define XML_H
00026
00027 #include <string>
00028 #include <list>
00029 #include <ctype.h>
00030
00031 class XmlNode {
00032 private:
00033 static std::string parseTag(std::string::iterator& curr, std::string::iterator end);
00034 static void skipWS(std::string::iterator& curr, std::string::iterator end);
00035
00036 protected:
00037 std::string tag;
00038
00039 XmlNode(const std::string& t);
00040
00041 public:
00042 virtual ~XmlNode();
00043
00044 virtual bool isBranch() = 0;
00045 bool isLeaf();
00046
00047 std::string getTag();
00048
00049 static XmlNode *parse(std::string::iterator& start, std::string::iterator end);
00050
00051 static std::string quote(const std::string& s);
00052 static std::string unquote(const std::string& s);
00053 static std::string replace_all(const std::string& s, const std::string& r1, const std::string& r2);
00054
00055 virtual std::string toString(int n) = 0;
00056 };
00057
00058 class XmlLeaf;
00059
00060 class XmlBranch : public XmlNode {
00061 private:
00062 std::list<XmlNode*> children;
00063
00064 public:
00065 XmlBranch(const std::string& t);
00066 ~XmlBranch();
00067
00068 bool isBranch();
00069 bool exists(const std::string& tag);
00070 XmlNode *getNode(const std::string& tag);
00071 XmlBranch *getBranch(const std::string& tag);
00072 XmlLeaf *getLeaf(const std::string& tag);
00073
00074 void pushnode(XmlNode *c);
00075
00076 std::string toString(int n);
00077
00078 };
00079
00080 class XmlLeaf : public XmlNode {
00081 private:
00082 std::string value;
00083 public:
00084 XmlLeaf(const std::string& t, const std::string& v);
00085 ~XmlLeaf();
00086
00087 bool isBranch();
00088 std::string getValue();
00089
00090 std::string toString(int n);
00091 };
00092
00093 #endif
00094