Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXXML.h
1 /********************************************************************************
2 * *
3 * X M L R e a d e r & W r i t e r *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2016,2022 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXXML_H
22 #define FXXML_H
23 
24 #ifndef FXPARSEBUFFER_H
25 #include "FXParseBuffer.h"
26 #endif
27 
28 namespace FX {
29 
30 
34 class FXAPI FXXML : public FXParseBuffer {
35 public:
36  enum Error {
37  ErrOK,
51  ErrEof
52  };
53  enum {
54  CRLF = 0x0001,
55  REFS = 0x0002,
56  };
57  enum {
58  UTF8 = 1,
59  UTF16LE = 2,
60  UTF16BE = 3,
61  UTF32LE = 4,
62  UTF32BE = 5
63  };
64 protected:
65  class Element; // Element info
66 protected:
67  FXlong offset; // Position from start
68  Element *current; // Current element instance
69  FXint column; // Column number
70  FXint line; // Line number
71  FXString vers; // Version
72  FXuint enc; // Encoding
73 private:
74  FXuint guess();
75  void spaces();
76  FXbool name();
77  FXbool match(FXchar ch);
78  FXbool match(const FXchar* str,FXint len);
79  Error parsestring(FXString& str);
80  Error parsexml();
81  Error parseversion();
82  Error parseencoding();
83  Error parsestandalone();
84  Error parseelementdecl();
85  Error parseexternalid();
86  Error parseinternalsubset();
87  Error parsedeclarations();
88  Error parseprocessing();
89  Error parsecomment();
90  Error parseattribute(Element& elm);
91  Error parsestarttag(Element& elm);
92  Error parseendtag(Element& elm);
93  Error parsecdata(Element& elm);
94  Error parsecontents(Element& elm);
95  Error parseelement();
96 private:
97  static const FXchar *const errors[];
98 private:
99  FXXML(const FXXML&);
100  FXXML& operator=(const FXXML&);
101 public:
102 
105 
108 
111 
114 
117 
120 
123 
124 public:
125 
129  FXXML();
130 
135  FXXML(FXchar* buffer,FXuval sz=4096,Direction d=Load);
136 
141  FXbool open(FXchar* buffer=nullptr,FXuval sz=4096,Direction d=Load);
142 
146  FXuval size() const { return endptr-begptr; }
147 
151  Direction direction() const { return dir; }
152 
156  FXint getLine() const { return line; }
157 
161  FXint getColumn() const { return column; }
162 
166  FXlong getOffset() const { return offset; }
167 
172  Error parse();
173 
175  Error startDocument();
176 
178  Error startElement(const FXString& tag);
179 
181  Error startElement(const FXString& tag,const FXStringDictionary& atts);
182 
184  Error characters(const FXString& text);
185 
187  Error comment(const FXString& text);
188 
190  Error processing(const FXString& target,const FXString& text);
191 
193  Error endElement(const FXString& tag);
194 
196  Error endDocument();
197 
199  static const FXchar* getError(Error err){ return errors[err]; }
200 
204  FXbool close();
205 
209  static FXbool decode(FXString& dst,const FXString& src,FXuint flags=CRLF|REFS);
210 
214  static FXbool encode(FXString& dst,const FXString& src,FXuint flags=CRLF|REFS);
215 
219  virtual ~FXXML();
220  };
221 
222 }
223 
224 #endif
Expected semicolon.
Definition: FXXML.h:49
The XML serializer loads or saves data to xml text file.
Definition: FXXML.h:34
No errors.
Definition: FXXML.h:38
FXCallback< Error(const FXString &) > commentCB
Called to pass comment string.
Definition: FXXML.h:113
Illegal token.
Definition: FXXML.h:46
FXint getLine() const
Return current line number.
Definition: FXXML.h:156
No data loaded.
Definition: FXXML.h:39
FXCallback< Error(const FXString &) > charactersCB
Called to pass batch of decoded characters.
Definition: FXXML.h:110
FXuval size() const
Return size of parse buffer.
Definition: FXXML.h:146
Unable to load.
Definition: FXXML.h:41
Expected space.
Definition: FXXML.h:42
Expected equals sign &#39;=&#39;.
Definition: FXXML.h:43
FXCallback< Error(const FXString &, const FXString &) > processingCB
Called to pass processing instruction.
Definition: FXXML.h:116
Expected name.
Definition: FXXML.h:44
static const FXchar * getError(Error err)
Returns error code for given error.
Definition: FXXML.h:199
FXCallback< Error(const FXString &, const FXStringDictionary &) > startElementCB
Called when start of element is recognized.
Definition: FXXML.h:107
Direction
Definition: FXParseBuffer.h:36
Expected hex digit.
Definition: FXXML.h:48
Error
Definition: FXXML.h:36
Definition: FX4Splitter.h:28
Unknown reference.
Definition: FXXML.h:50
Expected string.
Definition: FXXML.h:45
Direction direction() const
Return direction in effect.
Definition: FXXML.h:151
FXint getColumn() const
Return current column number.
Definition: FXXML.h:161
FXParseBuffer manages pointers to a buffer for various file format parsers.
Definition: FXParseBuffer.h:34
FXCallback< Error() > endDocumentCB
Called when end of document is recognized.
Definition: FXXML.h:122
FXCallback< Error(const FXString &) > endElementCB
Called when end of element is recognized.
Definition: FXXML.h:119
FXlong getOffset() const
Return offset from begin of file.
Definition: FXXML.h:166
FXCallback< Error() > startDocumentCB
Called when start of document is recognized.
Definition: FXXML.h:104
Unable to save.
Definition: FXXML.h:40
The dictionary class maintains a fast-access hash table of entities indexed by a character string...
Definition: FXStringDictionary.h:31
Expected digit.
Definition: FXXML.h:47
FXString provides essential string manipulation capabilities in FOX.
Definition: FXString.h:42

Copyright © 1997-2022 Jeroen van der Zijp