00001 #ifndef PHX_XML_H
00002 #define PHX_XML_H
00003
00004 #include <Phx/PhxConfig.h>
00005 #include <Phx/PhxTypes.h>
00006 #include <xercesc/dom/DOM.hpp>
00007 #include <vector>
00008
00009 namespace Phx {
00010
00011 XERCES_CPP_NAMESPACE_USE
00012
00013 class XmlNode;
00014 class XmlFile;
00019 class XmlDocument {
00020 friend class XmlFile;
00021 public:
00026 XmlDocument(const String& name);
00027
00028 ~XmlDocument();
00029
00033 void xmlString(const String& xmlData);
00034
00039 String xmlString();
00040
00044 void dtdString(const String& dtdString);
00045
00046 String dtdString();
00047
00048 XmlNode* rootNode();
00049
00053 String version ();
00054
00060 void version(const String& version);
00061
00065 String encoding ();
00066
00072 void encoding(const String& encoding);
00073
00077 bool standalone ();
00078
00084 void standalone(bool standalone);
00085
00086 bool valid();
00087
00088 protected:
00089 DOMDocument* mDoc;
00090 XmlDocument(DOMDocument* doc);
00091
00092 private:
00093 String mDTDString;
00094 XmlNode* mRoot;
00095 };
00096
00097 class XmlFile {
00098 public:
00103 XmlFile(const String& fname);
00104 ~XmlFile();
00105
00106 XmlDocument* xmlDocument();
00107 void xmlDocument(XmlDocument* document);
00108
00109 private:
00110 XmlDocument* mDocument;
00111 String mFname;
00112 };
00113
00114
00118 class XmlNode : public LockedPtrInterface <XmlNode> {
00119 friend class XmlDocument;
00120 private:
00121 XmlNode(DOMDocument* doc, DOMElement* node);
00122
00123
00124 XmlNode(XmlNode&);
00125 XmlNode& operator=(XmlNode&);
00126
00127 public:
00128 class Attribute {
00129 public:
00130 Attribute(const String& name, const String& value);
00131
00132
00133 const String& name() const { return mName; }
00134 const String& value() const { return mValue; }
00135
00136 void name(const String& name) { mName = name; }
00137 void value(const String& value) { mValue = value; }
00138
00139 private:
00140 String mName;
00141 String mValue;
00142 };
00143
00144
00145 ~XmlNode();
00146
00147
00148 String name() const;
00149
00150
00151 uint32_t attributeCount() const;
00152
00153
00154
00155 Attribute attribute(uint32_t index) const;
00156
00157
00158 String attribute(const String& name);
00159
00160
00161 void attribute(const String& name, const String& value);
00162
00167 uint32_t childCount() const;
00168
00169 XmlNode* child(uint32_t index);
00170 const XmlNode* child(uint32_t index) const;
00171 XmlNode* newChild(const String& tag);
00172 void deleteChild(uint32_t index);
00173
00177 String text() const;
00178
00183 void text(const String& text);
00184
00185 private:
00186 DOMElement* mNode;
00187 DOMDocument* mDoc;
00188 std::vector<XmlNode*> mChildren;
00189 };
00190
00191 }
00192 #endif // PHX_XML_H