UCommon
xml.h
Go to the documentation of this file.
1 // Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
2 // Copyright (C) 2015 Cherokees of Idaho.
3 //
4 // This file is part of GNU uCommon C++.
5 //
6 // GNU uCommon C++ is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Lesser General Public License as published
8 // by the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // GNU uCommon C++ is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.
18 
24 #ifndef _UCOMMON_STRING_H_
25 #include <ucommon/string.h>
26 #endif
27 
28 #ifndef _UCOMMON_PROTOCOLS_H_
29 #include <ucommon/protocols.h>
30 #endif
31 
32 #ifndef _UCOMMON_XML_H_
33 #define _UCOMMON_XML_H_
34 
35 namespace ucommon {
36 
48 class __EXPORT XMLParser
49 {
50 private:
51  int ecount, dcount;
52  enum {TAG, CDATA, COMMENT, DTD, AMP, NONE, END} state;
53  char *buffer;
54  unsigned bufpos, bufsize;
55  __LOCAL bool parseTag(void);
56  __LOCAL void putBuffer(char c);
57  __LOCAL void clearBuffer(void);
58 
59  __DELETE_COPY(XMLParser);
60 
61 protected:
66  XMLParser(unsigned size = 8192);
67 
71  virtual ~XMLParser();
72 
78  virtual void comment(caddr_t text, size_t size);
79 
85  virtual void characters(caddr_t text, size_t size);
86 
90  virtual void startDocument(void);
91 
95  virtual void endDocument(void);
96 
102  virtual void startElement(caddr_t name, caddr_t *attr) = 0;
103 
108  virtual void endElement(caddr_t name) = 0;
109 
119  bool partial(const char *address, size_t size);
120 
130  bool parse(CharacterProtocol& stream);
131 
141  bool parse(FILE *file);
142 
147  bool end(void) const {
148  return state == END;
149  }
150 };
151 
152 } // namespace ucommon
153 
154 #endif
A common string class and character string support functions.
Access standard files through character protocol.
Definition: file.h:60
bool end(void) const
End of document check.
Definition: xml.h:147
Common namespace for all ucommon objects.
Definition: access.h:47
Abstract interfaces and support.
XML streaming parser.
Definition: xml.h:48
Common character processing protocol.
Definition: protocols.h:175