Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

Xml.h

00001 /*
00002  * XML Parser/Generator
00003  * Simple XML parser/generator sufficient to
00004  * send+receive the XML in ICQ SMS messages
00005  *
00006  * Copyright (C) 2001 Barnaby Gray <barnaby@beedesign.co.uk>.
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
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 

Generated on Sun Jul 21 10:57:32 2002 for libicq2000 by doxygen1.2.16