Adapted to recent changes of %build_linklib.
[AROS-Contrib.git] / FryingPan / framework / Generic / XMLDocument.h
blobe7bc6c3f69b28dbeed69761426f289068c172415
1 /*
2 * Amiga Generic Set - set of libraries and includes to ease sw development for all Amiga platforms
3 * Copyright (C) 2001-2011 Tomasz Wiszkowski Tomasz.Wiszkowski at gmail.com.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #ifndef XMLDATA_H_
21 #define XMLDATA_H_
23 #include "LibrarySpool.h"
24 #include "String.h"
25 #include "VectorT.h"
27 #include <libdata/expat.h>
30 * this class relies on expat2.library (both binary and include files) that i have created...
33 struct Expat2IFace;
35 namespace GenNS
37 class XMLAttribute
39 protected:
40 String sName;
41 String sValue;
43 protected:
44 virtual void Initialize(const char* sN, const char* sV);
45 virtual void Initialize(const char* sN, int64 lV);
47 public:
48 XMLAttribute();
49 XMLAttribute(const char* sName, const char* sValue);
50 XMLAttribute(const char* sName, int64 sValue);
51 virtual ~XMLAttribute();
53 virtual String &GetName();
54 virtual String &GetValue();
55 virtual void SetName(const char* sName);
56 virtual void SetValue(const char* sValue);
57 virtual void SetValue(uint64 sValue);
60 class XMLElement : public XMLAttribute
62 protected:
63 VectorT<XMLElement*> hChildren;
64 VectorT<XMLAttribute*> hAttributes;
66 protected:
67 virtual void Initialize(const char* sN, const char* sV);
68 static bool freeAttr(XMLAttribute* const& attr);
69 static bool freeNode(XMLElement* const& node);
70 public:
71 XMLElement();
72 XMLElement(const char* sName, const char* sValue);
73 virtual ~XMLElement();
75 virtual long GetChildrenCount();
76 virtual XMLElement *GetChild(long i);
77 virtual long GetAttributesCount();
78 virtual XMLAttribute *GetAttribute(long i);
79 virtual String *GetChildValue(const char *sName);
80 virtual String *GetAttributeValue(const char *sName);
81 virtual XMLElement *FindChild(const char* sName);
82 virtual XMLAttribute *FindAttribute(const char* sName);
84 virtual XMLElement *AddChild(const char* sName, const char* sValue);
85 virtual XMLAttribute *AddAttribute(const char* sName, const char* sValue);
86 virtual XMLAttribute *AddAttribute(const char* sName, int64 lValue);
87 virtual XMLElement *AddChild(XMLElement* pElem);
88 virtual XMLAttribute *AddAttribute(XMLAttribute *pAttr);
89 virtual void RemChild(XMLElement* pElem);
90 virtual void RemAttribute(XMLAttribute* pAttr);
93 class XMLDocument : public XMLElement
95 public:
96 enum XMLError
98 XErr_OK = 0, // all ok
99 XErr_NoExpat, // unable to open expat2.library
100 XErr_NoFile, // unable to open file
101 XErr_NoMemory, // not enough memory
102 XErr_CorruptedXML, // corrupted xml file
103 XErr_NoParser // unable to create parser
106 protected:
107 Expat2IFace *pExpat;
108 String sFileName;
109 XML_Parser pParser;
110 XMLError eError;
111 int level;
113 VectorT<XMLElement*> hParse;
115 static void fXMLStartHandler(void* userData, const XML_Char *name, const XML_Char **atts);
116 static void fXMLEndHandler(void* userData, const XML_Char *name);
117 static void fXMLContentHandler(void* userData, const XML_Char *begin, int length);
118 void XMLStartHandler(const XML_Char *name, const XML_Char **atts);
119 void XMLEndHandler(const XML_Char *name);
120 void XMLContentHandler(const XML_Char *begin, int length);
121 void XMLWriteElement(BPTR fh, XMLElement* pElem);
122 public:
123 XMLDocument();
124 XMLDocument(const char* sName);
125 virtual ~XMLDocument();
127 bool ReadXML(const char *sName);
128 bool WriteXML(const char *sName);
129 bool ReadXML(BPTR file);
130 bool WriteXML(BPTR file);
131 XMLError GetError();
135 #endif /*XMLDATA_H_*/