XmlElement.h

Go to the documentation of this file.
00001 #ifndef __XMLELEMENT_H__
00002 #define __XMLELEMENT_H__
00003 
00004 /*
00005 
00006 $Id$
00007 
00008 */
00009 
00010 #include <map>
00011 #include <vector>
00012 
00013 #include "Support.h"
00014 #include "String.h"
00015 #include "XmlAttribute.h"
00016 
00017 // Messages.
00018 
00019 static const char *const MSG_XML_ELEMENT_ATTR_NOT_FOUND = "XML element does not have attribute '%s'.";
00020 static const char *const MSG_XML_ELEMENT_NOT_FOUND      = "XML element not found.";
00021 
00022 // Common attributes.
00023 
00024 static const char *const XML_ATTR_ID      = "id";
00025 static const char *const XML_ATTR_NAME    = "name";
00026 static const char *const XML_ATTR_TYPE    = "type";
00027 static const char *const XML_ATTR_VALUE   = "value";
00028 static const char *const XML_ATTR_DEFAULT = "default";
00029 
00030 static const unsigned int XML_INDENT = 2;
00031 
00032 using namespace std;
00033 
00034 class XmlElement;
00035 class XmlDocument;
00036 
00037 typedef map<String, String> XmlAttributeCollection;
00038 typedef vector<XmlElement *> XmlElementCollection;
00039 
00040 class XmlElement : public Support
00041 {
00042 
00043 friend class XmlDocument;
00044 
00045 public:
00046 
00047   XmlElement(const String &tag,
00048              XmlAttribute *attr = NULL, const String &innerData = "",
00049              XmlElement* nextChild = NULL, XmlElement *nextSibling = NULL);
00050 
00051   virtual ~XmlElement();
00052 
00053   String tag() const;
00054 
00055   String id() const;
00056   int setId(const String &id);
00057 
00058   String name() const;
00059   int setName(const String &name);
00060 
00061   int attribute(const String &name, String &value) const;
00062   XmlAttributeCollection atributes() const;
00063   int setAttribute(const String &name, const String &value);
00064 
00065   bool hasChildren() const;
00066   XmlElementCollection *children() const;
00067   int appendChild(XmlElement *element);
00068   int detachChild(XmlElement *element);
00069   int removeChild(XmlElement *element);
00070   int removeChildren();
00071 
00072   XmlDocument *document() const;
00073   XmlElement *parent() const;
00074 
00075   String innerData() const;
00076   int setInnerData(const String &data);
00077   int appendInnerData(const String &data);
00078 
00079   int toString(String &str) const;
00080 
00081 protected:
00082 
00083   virtual int close();
00084 
00085 private:
00086 
00087   int setDocument(const XmlDocument *doc);
00088   int setParent(const XmlElement *parent);
00089   int _toString(String &str, unsigned int &indent) const;
00090 
00091   String _tag;
00092   XmlDocument *_document;
00093   XmlElement *_parent;
00094   XmlElement *_nextSibling;
00095   String _innerData;
00096   XmlAttributeCollection _attributes;
00097   XmlElementCollection _children;
00098 };
00099 
00100 #endif

Generated on Thu Sep 6 20:11:25 2007 for Pylon Application Platform by  doxygen 1.5.1