ObjFW
OFXMLParser.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015
3  * Jonathan Schleifer <js@webkeks.org>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #import "OFObject.h"
18 #import "OFString.h"
19 #import "OFXMLAttribute.h"
20 
21 OF_ASSUME_NONNULL_BEGIN
22 
23 @class OFXMLParser;
24 #ifndef DOXYGEN
25 @class OFArray OF_GENERIC(ObjectType);
26 @class OFMutableArray OF_GENERIC(ObjectType);
27 @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
28 #endif
29 @class OFDataArray;
30 @class OFStream;
31 
38 #ifdef OF_HAVE_OPTIONAL_PROTOCOLS
39 @optional
40 #endif
41 
48 - (void)parser: (OFXMLParser*)parser
49  foundProcessingInstructions: (OFString*)pi;
50 
62 - (void)parser: (OFXMLParser*)parser
63  didStartElement: (OFString*)name
64  prefix: (nullable OFString*)prefix
65  namespace: (nullable OFString*)ns
66  attributes: (nullable OFArray OF_GENERIC(OFXMLAttribute*)*)attributes;
67 
76 - (void)parser: (OFXMLParser*)parser
77  didEndElement: (OFString*)name
78  prefix: (nullable OFString*)prefix
79  namespace: (nullable OFString*)ns;
80 
90 - (void)parser: (OFXMLParser*)parser
91  foundCharacters: (OFString*)characters;
92 
99 - (void)parser: (OFXMLParser*)parser
100  foundCDATA: (OFString*)CDATA;
101 
108 - (void)parser: (OFXMLParser*)parser
109  foundComment: (OFString*)comment;
110 
123 - (OFString*)parser: (OFXMLParser*)parser
124  foundUnknownEntityNamed: (OFString*)entity;
125 @end
126 
136 {
137  id <OFXMLParserDelegate> _delegate;
138  enum {
139  OF_XMLPARSER_IN_BYTE_ORDER_MARK,
140  OF_XMLPARSER_OUTSIDE_TAG,
141  OF_XMLPARSER_TAG_OPENED,
142  OF_XMLPARSER_IN_PROCESSING_INSTRUCTIONS,
143  OF_XMLPARSER_IN_TAG_NAME,
144  OF_XMLPARSER_IN_CLOSE_TAG_NAME,
145  OF_XMLPARSER_IN_TAG,
146  OF_XMLPARSER_IN_ATTRIBUTE_NAME,
147  OF_XMLPARSER_EXPECT_ATTRIBUTE_EQUAL_SIGN,
148  OF_XMLPARSER_EXPECT_ATTRIBUTE_DELIMITER,
149  OF_XMLPARSER_IN_ATTRIBUTE_VALUE,
150  OF_XMLPARSER_EXPECT_TAG_CLOSE,
151  OF_XMLPARSER_EXPECT_SPACE_OR_TAG_CLOSE,
152  OF_XMLPARSER_IN_EXCLAMATIONMARK,
153  OF_XMLPARSER_IN_CDATA_OPENING,
154  OF_XMLPARSER_IN_CDATA,
155  OF_XMLPARSER_IN_COMMENT_OPENING,
156  OF_XMLPARSER_IN_COMMENT_1,
157  OF_XMLPARSER_IN_COMMENT_2,
158  OF_XMLPARSER_IN_DOCTYPE,
159  OF_XMLPARSER_NUM_STATES
160  } _state;
161  size_t _i, _last;
162  const char *_data;
163  OFDataArray *_buffer;
164  OFString *_name, *_prefix;
166  OF_GENERIC(OFMutableDictionary OF_GENERIC(OFString*, OFString*)*)
167  *_namespaces;
168  OFMutableArray OF_GENERIC(OFXMLAttribute*) *_attributes;
169  OFString *_attributeName, *_attributePrefix;
170  char _delimiter;
171  OFMutableArray OF_GENERIC(OFString*) *_previous;
172  size_t _level;
173  bool _acceptProlog;
174  size_t _lineNumber;
175  bool _lastCarriageReturn, _finishedParsing;
176  of_string_encoding_t _encoding;
177  size_t _depthLimit;
178 }
179 
180 #ifdef OF_HAVE_PROPERTIES
181 @property OF_NULLABLE_PROPERTY (assign) id <OFXMLParserDelegate> delegate;
182 @property size_t depthLimit;
183 #endif
184 
190 + (instancetype)parser;
191 
197 - (void)setDelegate: (nullable id <OFXMLParserDelegate>)delegate;
198 
204 - (nullable id <OFXMLParserDelegate>)delegate;
205 
211 - (size_t)depthLimit;
212 
222 - (void)setDepthLimit: (size_t)depthLimit;
223 
230 - (void)parseBuffer: (const char*)buffer
231  length: (size_t)length;
232 
238 - (void)parseString: (OFString*)string;
239 
245 - (void)parseStream: (OFStream*)stream;
246 
247 #ifdef OF_HAVE_FILES
248 
253 - (void)parseFile: (OFString*)path;
254 #endif
255 
261 - (size_t)lineNumber;
262 
268 - (bool)finishedParsing;
269 @end
270 
271 @interface OFObject (OFXMLParserDelegate) <OFXMLParserDelegate>
272 @end
273 
274 OF_ASSUME_NONNULL_END
An abstract class for storing objects in an array.
Definition: OFArray.h:95
A representation of an attribute of an XML element as an object.
Definition: OFXMLAttribute.h:28
of_string_encoding_t
The encoding of a string.
Definition: OFString.h:50
The root class for all other classes inside ObjFW.
Definition: OFObject.h:364
An abstract class for storing, adding and removing objects in an array.
Definition: OFMutableArray.h:46
A base class for different types of streams.
Definition: OFStream.h:86
A class for handling strings.
Definition: OFString.h:91
A class for storing arbitrary data in an array.
Definition: OFDataArray.h:37
A protocol that needs to be implemented by delegates for stringByXMLUnescapingWithHandler:.
Definition: OFString+XMLUnescaping.h:50
An abstract class for storing and changing objects in a dictionary.
Definition: OFMutableDictionary.h:47
A protocol that needs to be implemented by delegates for OFXMLParser.
Definition: OFXMLParser.h:37
An event-based XML parser.
Definition: OFXMLParser.h:135