UCommon
xml.h
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 
25 #ifndef COMMONCPP_XML_H_
26 #define COMMONCPP_XML_H_
27 
28 #ifndef COMMONCPP_CONFIG_H_
29 #include <commoncpp/config.h>
30 #endif
31 
32 namespace ost {
33 
45 class __EXPORT XMLParser
46 {
47 private:
48  int ecount, dcount;
49  enum {TAG, CDATA, COMMENT, DTD, AMP, NONE, END} state;
50  char *buffer;
51  unsigned bufpos, bufsize;
52  __LOCAL bool parseTag(void);
53  __LOCAL void putBuffer(char c);
54  __LOCAL void clearBuffer(void);
55 
56  __DELETE_COPY(XMLParser);
57 
58 protected:
63  XMLParser(unsigned size = 8192);
64 
68  virtual ~XMLParser();
69 
75  virtual void comment(const caddr_t text, size_t size);
76 
82  virtual void characters(const caddr_t text, size_t size);
83 
87  virtual void startDocument(void);
88 
92  virtual void endDocument(void);
93 
99  virtual void startElement(const caddr_t name, caddr_t *attr) = 0;
100 
105  virtual void endElement(const caddr_t name) = 0;
106 
116  bool partial(const char *address, size_t size);
117 
127  bool parse(const char *cp);
128 
138  bool parse(FILE *file);
139 
144  bool end(void) const {
145  return state == END;
146  }
147 };
148 
149 } // namespace ucommon
150 
151 #endif
ost::XMLParser::comment
virtual void comment(const caddr_t text, size_t size)
Virtual to receive embedded comments in XML document being parsed.
ost::XMLParser
XML streaming parser.
Definition: xml.h:46
ost::XMLParser::startDocument
virtual void startDocument(void)
Notify start of document event.
ost::XMLParser::end
bool end(void) const
End of document check.
Definition: xml.h:144
ost::XMLParser::endElement
virtual void endElement(const caddr_t name)=0
Notify end of an element in the document.
ost::XMLParser::characters
virtual void characters(const caddr_t text, size_t size)
Virtual to receive character text extracted from the document.
ost::XMLParser::parse
bool parse(FILE *file)
Parse a file buffer and return parser document completion flag.
ost::XMLParser::partial
bool partial(const char *address, size_t size)
Parse a chunk of data and return parser completion flag.
ost::XMLParser::parse
bool parse(const char *cp)
Parse a stream buffer and return parser document completion flag.
ost::XMLParser::startElement
virtual void startElement(const caddr_t name, caddr_t *attr)=0
Notify start of an element in the document.
ost::XMLParser::XMLParser
XMLParser(unsigned size=8192)
Create xml parser.
ost::XMLParser::~XMLParser
virtual ~XMLParser()
Destroy xml parser.
ost::XMLParser::endDocument
virtual void endDocument(void)
Notify end of document event.