ObjFW
 All Classes Functions Variables
OFXMLParser.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012
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 @class OFXMLParser;
22 @class OFArray;
23 @class OFMutableArray;
24 @class OFDataArray;
25 @class OFStream;
26 
30 #ifndef OF_XML_PARSER_M
32 #else
33 @protocol OFXMLParserDelegate
34 #endif
35 #ifdef OF_HAVE_OPTIONAL_PROTOCOLS
36 @optional
37 #endif
38 
45 - (void)parser: (OFXMLParser*)parser
46  foundProcessingInstructions: (OFString*)pi;
47 
59 - (void)parser: (OFXMLParser*)parser
60  didStartElement: (OFString*)name
61  withPrefix: (OFString*)prefix
62  namespace: (OFString*)ns
63  attributes: (OFArray*)attributes;
64 
73 - (void)parser: (OFXMLParser*)parser
74  didEndElement: (OFString*)name
75  withPrefix: (OFString*)prefix
76  namespace: (OFString*)ns;
77 
87 - (void)parser: (OFXMLParser*)parser
88  foundCharacters: (OFString*)characters;
89 
96 - (void)parser: (OFXMLParser*)parser
97  foundCDATA: (OFString*)CDATA;
98 
105 - (void)parser: (OFXMLParser*)parser
106  foundComment: (OFString*)comment;
107 
120 - (OFString*)parser: (OFXMLParser*)parser
121  foundUnknownEntityNamed: (OFString*)entity;
122 @end
123 
131 {
132  id <OFXMLParserDelegate> delegate;
133  enum {
134  OF_XMLPARSER_OUTSIDE_TAG,
135  OF_XMLPARSER_TAG_OPENED,
136  OF_XMLPARSER_IN_PROCESSING_INSTRUCTIONS,
137  OF_XMLPARSER_IN_TAG_NAME,
138  OF_XMLPARSER_IN_CLOSE_TAG_NAME,
139  OF_XMLPARSER_IN_TAG,
140  OF_XMLPARSER_IN_ATTR_NAME,
141  OF_XMLPARSER_EXPECT_DELIM,
142  OF_XMLPARSER_IN_ATTR_VALUE,
143  OF_XMLPARSER_EXPECT_CLOSE,
144  OF_XMLPARSER_EXPECT_SPACE_OR_CLOSE,
145  OF_XMLPARSER_IN_EXCLAMATIONMARK,
146  OF_XMLPARSER_IN_CDATA_OPENING,
147  OF_XMLPARSER_IN_CDATA_1,
148  OF_XMLPARSER_IN_CDATA_2,
149  OF_XMLPARSER_IN_COMMENT_OPENING,
150  OF_XMLPARSER_IN_COMMENT_1,
151  OF_XMLPARSER_IN_COMMENT_2,
152  OF_XMLPARSER_IN_DOCTYPE,
153  OF_XMLPARSER_NUM_STATES
154  } state;
155  OFDataArray *cache;
156  OFString *name;
157  OFString *prefix;
158  OFMutableArray *namespaces;
159  OFMutableArray *attributes;
160  OFString *attributeName;
161  OFString *attributePrefix;
162  char delimiter;
163  OFMutableArray *previous;
164  size_t level;
165  BOOL acceptProlog;
166  size_t lineNumber;
167  BOOL lastCarriageReturn;
168  BOOL finishedParsing;
169  of_string_encoding_t encoding;
170 }
171 
172 #ifdef OF_HAVE_PROPERTIES
173 @property (assign) id <OFXMLParserDelegate> delegate;
174 #endif
175 
181 + (instancetype)parser;
182 
188 - (id <OFXMLParserDelegate>)delegate;
189 
195 - (void)setDelegate: (id <OFXMLParserDelegate>)delegate;
196 
203 - (void)parseBuffer: (const char*)buffer
204  length: (size_t)length;
205 
211 - (void)parseString: (OFString*)string;
212 
218 - (void)parseStream: (OFStream*)stream;
219 
225 - (void)parseFile: (OFString*)path;
226 
232 - (size_t)lineNumber;
233 
239 - (BOOL)finishedParsing;
240 @end
241 
242 @interface OFObject (OFXMLParserDelegate) <OFXMLParserDelegate>
243 @end