Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

PhxXml.h

00001 #ifndef PHX_XML_H
00002 #define PHX_XML_H
00003 
00004 #include <Phx/Core/PhxCore.h>
00005 
00006 #include <map>
00007 #include <vector>
00008 
00009 namespace Phx
00010 {
00014   enum XmlNodeType
00015   {
00016     XML_NODE_TYPE_UNKOWN, XML_NODE_TYPE_ELEMENT,
00017     XML_NODE_TYPE_TEXT, XML_NODE_TYPE_COMMENT
00018   };
00019 
00020   class XmlNode;
00021   class XmlElementNode;
00022 
00027   class XmlDocument
00028   {
00029   private:
00030     typedef std::map<String, String> type_mapAttributes;
00031     //Contains the values of encoding, version... if present.
00032     type_mapAttributes m_mapAtributes;
00033 
00034     XmlNode * pRootNode;
00035 
00036     String printChildNodes(XmlElementNode* rootNode);
00037 
00038   public:
00044     XmlDocument(XmlNode* rootNode):pRootNode(rootNode){}
00045 
00050     XmlDocument(const String& xmlData);
00051 
00055     XmlDocument(){}
00056 
00061     void xmlString(const String& xmlData);
00062 
00066     String xmlString();
00067 
00073     void setRootNode(XmlNode* rootNode){pRootNode=rootNode;}
00074     XmlNode * getRootNode (){return pRootNode;}
00078     String getVersion ();
00079 
00085     void setVersion(const String& version);
00086 
00090     String getEncoding ();
00091 
00097     void setEncoding(const String& encoding);
00098 
00102     String getStandalone ();
00103 
00109     void setStandalone(const String& standalone);
00110 
00118     String getAttribute(const String& attribute);
00119 
00126     void setAttribute(const String& attribute, const String& value);
00127 
00128 
00129     bool hasAttribute();
00130   };
00131 
00132   class XmlFile
00133   {
00134   public:
00140     XmlFile(const String& fname);
00141 
00145     XmlDocument* xmlDocument();
00146 
00147     void xmlDocument(XmlDocument* document);
00148 
00149   private:
00150     bool mLoaded;
00151     XmlDocument* mDocument;
00152     String mFname;
00153   };
00154 
00158   class XmlNode
00159   {
00160   protected:
00161     XmlNodeType mType;
00162   public:
00163     XmlNodeType getType(){return mType;}
00164     bool hasChild(){return false;}
00165     bool hasAttribute(){return false;}
00166   };
00167 
00171   class XmlUnkownNode:public XmlNode
00172   {
00173   private:
00174     String mData;
00175   public:
00176     XmlUnkownNode(){XmlNode::mType = XML_NODE_TYPE_UNKOWN;}
00177     void setData (const String& newData);
00178     String getData () const {return mData;}
00179   };
00180 
00184   class XmlTextNode:public XmlNode
00185   {
00186   private:
00187     String mData;
00188   public:
00189     XmlTextNode()
00190     {XmlNode::mType = XML_NODE_TYPE_TEXT;}
00191 
00192     XmlTextNode(const String& data):mData(data)
00193     {XmlNode::mType = XML_NODE_TYPE_TEXT;}
00194 
00195     void setData (const String& newData);
00196     String getData () const {return mData;}
00197   };
00198 
00202   class XmlCommentNode:public XmlNode
00203   {
00204   private:
00205     String mData;
00206 
00207   public:
00208     XmlCommentNode()
00209     {XmlNode::mType = XML_NODE_TYPE_COMMENT;}
00210 
00211     XmlCommentNode(const String& data):mData(data)
00212     {XmlNode::mType = XML_NODE_TYPE_COMMENT;}
00213 
00214     void setData (const String& newData);
00215     String getData (){return mData;}
00216   };
00217 
00221   class XmlElementNode:public XmlNode
00222   {
00223   private:
00224     String mName;
00225 
00226     typedef std::map<String, String> type_mapAttributes;
00227     type_mapAttributes m_mapAttributes;
00228 
00229     typedef std::vector<XmlNode*> type_listOfNodes;
00230     //List of child nodes
00231     type_listOfNodes m_listOfNodes;
00232 
00233   public:
00234     XmlElementNode(const String& name):mName(name)
00235     {XmlNode::mType = XML_NODE_TYPE_ELEMENT;}
00236 
00237     void insertChildNode (XmlNode * insertThis);
00238     void removeChildNode (int index);
00239 
00240     int getNumberOfChildNodes();
00241 
00245     XmlNode* getChildNode(int index);
00246 
00247     void setAttribute (const String& newName, const String& newValue);
00248     String getAttribute(const String& name);
00249     void removeAttribute(const String& name);
00250 
00254     String printAttribute();
00255 
00256     bool hasChild();
00257     bool hasAttribute();
00258 
00259     String getName(){return mName;}
00260   };
00261 }
00262 #endif // PHX_XML_H

Generated on Wed Dec 21 22:05:37 2005 for Phoenix OSFS by  doxygen 1.4.2