XmlDocument.h

Go to the documentation of this file.
00001 #ifndef __XMLDOCUMENT_H__
00002 #define __XMLDOCUMENT_H__
00003 
00004 /*
00005 
00006 $Id$
00007 
00008 */
00009 
00010 #include <vector>
00011 
00012 #include "expat.h"
00013 
00014 #include "String.h"
00015 #include "XmlElement.h"
00016 
00017 // Messages.
00018 
00019 static const char *const MSG_XML_DOCUMENT_PARSER_CANNOT_CREATE = "Cannot create XML parser.";
00020 static const char *const MSG_XML_DOCUMENT_PARSER_CANNOT_RESET  = "Cannot reset XML parser.";
00021 static const char *const MSG_XML_DOCUMENT_PARSER               = "XML parser error '%s' at line %llu, column %llu.";
00022 static const char *const MSG_XML_DOCUMENT_ELEMENT_NOT_FOUND    = "Cannot find element with attribute '%s' == '%s'.";
00023 static const char *const MSG_XML_DOCUMENT_EMPTY                = "Document is empty.";
00024 
00025 // Attribute elements.
00026 
00027 static const char *const XML_ATTR_TAGS[] = {
00028   XML_ATTR_ID,
00029   XML_ATTR_NAME,
00030   XML_ATTR_TYPE,
00031   XML_ATTR_VALUE,
00032   XML_ATTR_DEFAULT,
00033   // End of list.
00034   NULL
00035 };
00036 
00037 class XmlDocument : public Support
00038 {
00039 
00040 public:
00041 
00042   XmlDocument();
00043   virtual ~XmlDocument();
00044 
00045   int reset();
00046   int parse(const char *data, const unsigned int size, const bool isFinal = true);
00047 
00048   int createElement(const String &tag, XmlElement **element, XmlAttribute *attr = NULL);
00049   int removeElement(XmlElement *element);
00050 
00051   XmlElement *root() const;
00052 
00053   int getElementById(const String &id, XmlElement **element) const;
00054   int getElementsByName(const String &name, XmlElementCollection &elements) const;
00055   int getElementsByTagName(const String &tag, XmlElementCollection &elements) const;
00056 
00057 private:
00058 
00059   static void XMLCALL start(void *document, const char *tag, const char **attrs);
00060   static void XMLCALL end(void *document, const char *tag);
00061   static void XMLCALL data(void *document, const XML_Char *str, int len);
00062 
00063   static int _getElementById(const String &id, XmlElement **element, bool &found);
00064   static int _getElementsByName(const String &name, XmlElement *element, XmlElementCollection &elements);
00065   static int _getElementsByTagName(const String &tag, XmlElement *element, XmlElementCollection &elements);
00066 
00067   XML_Parser _parser;
00068   XmlElement *_root;
00069   XmlElement *_current;
00070 };
00071 
00072 #endif

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