2
<!DOCTYPE gsdoc PUBLIC "-//GNUstep//DTD gsdoc 0.6.6//EN" "http://www.gnustep.org/gsdoc-0_6_6.xml">
3
<gsdoc base="GSXMLParser" prev="GSXMLAttribute" up="GSXML" next="GSSAXHandler">
5
<title>GSXMLParser</title>
6
<author name="Michael Pakhantsov">
7
<email address="mishel@berest.dp.ua"/>
9
<author name="Richard Frith-Macdonald">
10
<email address="rfm@gnu.org"/>
12
<version>$Revision: 1.9 $</version>
13
<date>$Date: 2001/03/03 09:58:53 $</date>
18
<heading>GSXMLParser</heading>
19
<class name="GSXMLParser" super="NSObject">
20
<declared>GSXML.h</declared>
23
The XML parser object is the pivotal part of parsing an XML
24
document - it will either build a tree representing the
25
document (if initialized without a GSSAXHandler), or will
26
cooperate with a GSSAXHandler object to provide parsing
27
without the overhead of building a tree.
30
The parser may be initialized with an input source (in which
31
case it will expect to be asked to parse the entire input in
32
a single operation), or without. If it is initialised without
33
an input source, incremental parsing can be done by feeding
34
successive parts of the XML document into the parser as
39
<method type="NSString*" factory="yes">
40
<sel>loadEntity:</sel>
41
<arg type="NSString*">publicID</arg>
43
<arg type="NSString*">locationURL</arg>
46
This method controls the loading of external entities into
47
the system. If it returns an empty string, the entity is not
48
loaded. If it returns a filename, the entity is loaded from
49
that file. If it returns nil, the default entity loading
53
The default entity loading mechanism is to construct a file
54
name from the locationURL, by replacing all path separators
55
with underscores, then attempt to locate that file in the DTDs
56
resource directory of the main bundle, and all the standard
60
As a special case, the default loader examines the publicID
61
and if it is a GNUstep DTD, the loader constructs a special
62
name from the ID (by replacing dots with underscores and
63
spaces with hyphens) and looks for a file with that name
64
and a '.dtd' extension in the GNUstep bundles.
67
NB. This method will only be called if there is no SAX
68
handler in use, or if the corresponding method in the
69
SAX handler returns nil.
74
<method type="GSXMLParser*" factory="yes">
78
Creation of a new Parser (for incremental parsing)
79
by calling initWithSAXHandler:
84
<method type="GSXMLParser*" factory="yes">
85
<sel>parserWithContentsOfFile:</sel>
86
<arg type="NSString*">path</arg>
89
Creation of a new Parser by calling
90
initWithSAXHandler:withContentsOfFile:
93
GSXMLParser *p = [GSXMLParser parserWithContentsOfFile: @"macos.xml"];
101
printf("error parse file\n");
108
<method type="GSXMLParser*" factory="yes">
109
<sel>parserWithContentsOfURL:</sel>
110
<arg type="NSURL*">url</arg>
113
Creation of a new Parser by calling
114
initWithSAXHandler:withContentsOfURL:
119
<method type="GSXMLParser*" factory="yes">
120
<sel>parserWithData:</sel>
121
<arg type="NSData*">data</arg>
123
<p>Creation of a new Parser by calling
124
initWithSAXHandler:withData:
129
<method type="GSXMlParser*" factory="yes">
130
<sel>parserWithSAXHandler:</sel>
131
<arg type="GSSAXHandler*">handler</arg>
134
Creation of a new Parser by calling initWithSAXHandler:
137
If the handler object supplied is nil, the parser will build
138
a tree representing the parsed file rather than attempting
139
to get the handler to deal with the parsed elements and entities.
144
<method type="GSXMlParser*" factory="yes">
145
<sel>parserWithSAXHandler:</sel>
146
<arg type="GSSAXHandler*">handler</arg>
147
<sel>withContentsOfFile:</sel>
148
<arg type="NSString*">path</arg>
151
Creation of a new Parser by calling
152
initWithSAXHandler:withContentsOfFile:
155
NSAutoreleasePool *arp = [[NSAutoreleasePool alloc] init];
156
GSSAXHandler *h = [GSDebugSAXHandler handler];
157
GSXMLParser *p = [GSXMLParser parserWithSAXHandler: h
158
withContentsOfFile: @"macos.xml"];
171
<method type="GSXMlParser*" factory="yes">
172
<sel>parserWithSAXHandler:</sel>
173
<arg type="GSSAXHandler*">handler</arg>
174
<sel>withContentsOfURL:</sel>
175
<arg type="NSURL*">url</arg>
178
Creation of a new Parser by calling
179
initWithSAXHandler:withContentsOfURL:
184
<method type="GSXMlParser*" factory="yes">
185
<sel>parserWithSAXHandler:</sel>
186
<arg type="GSSAXHandler*">handler</arg>
188
<arg type="NSData*">data</arg>
191
Creation of a new Parser by calling
192
initWithSAXHandler:withData:
197
<method type="NSString*" factory="yes">
198
<sel>xmlEncodingStringForStringEncoding:</sel>
199
<arg type="NSStringEncoding">encoding</arg>
201
Return the name of the string encoding (for XML) to use for the
202
specified OpenStep encoding.
206
<method type="id" init="yes">
207
<sel>initWithSAXHandler:</sel>
208
<arg type="GSSAXHandler*">handler</arg>
211
Initialisation of a new Parser with SAX handler (if not nil).
214
If the handler object supplied is nil, the parser will build
215
a tree representing the parsed file rather than attempting
216
to get the handler to deal with the parsed elements and entities.
219
The source for the parsing process is not specified - so
220
parsing must be done incrementally by feeding data to the
227
<sel>initWithSAXHandler:</sel>
228
<arg type="GSSAXHandler*">handler</arg>
229
<sel>withContentsOfFile:</sel>
230
<arg type="NSString*">path</arg>
233
Initialisation of a new Parser with SAX handler (if not nil)
234
by calling initWithSAXHandler:
237
Sets the input source for the parser to be the specified file -
238
so parsing of the entire file will be performed rather than
245
<sel>initWithSAXHandler:</sel>
246
<arg type="GSSAXHandler*">handler</arg>
247
<sel>withContentsOfURL:</sel>
248
<arg type="NSURL*">url</arg>
251
Initialisation of a new Parser with SAX handler (if not nil)
252
by calling initWithSAXHandler:
255
Sets the input source for the parser to be the specified URL -
256
so parsing of the entire document will be performed rather than
263
<sel>initWithSAXHandler:</sel>
264
<arg type="GSSAXHandler*">handler</arg>
266
<arg type="NSData*">data</arg>
269
Initialisation of a new Parser with SAX handler (if not nil)
270
by calling initWithSAXHandler:
273
Sets the input source for the parser to be the specified data
274
object (which must contain an XML document), so parsing of the
275
entire document will be performed rather than incremental parsing.
280
<method type="void*">
283
<p>Return pointer to xmlParserCtxt structure.
288
<method type="GSXMLDocument*">
292
Return GSXMLDocument object.
301
Parse source. Return YES if parsed, otherwise NO.
302
This method should be called once to parse the entire document.
305
GSXMLParser *p = [GSXMLParser parserWithContentsOfFile:@"macos.xml"];
313
printf("error parse file\n");
322
<arg type="NSData*">data</arg>
325
Pass data to the parser for incremental parsing. This method
326
should be called many times, with each call passing another
327
block of data from the same document. After the whole of the
328
document has been parsed, the method should be called with
329
an empty or nil data object to indicate end of parsing.
330
On this final call, the return value indicates whether the
331
document was valid or not.
334
GSXMLParser *p = [GSXMLParser parserWithSAXHandler: nil source: nil];
336
while ((data = getMoreData()) != nil)
338
if ([p parse: data] == NO)
340
NSLog(@"parse error");
343
// Do something with document parsed
345
[p parse: nil]; // Completed parsing of document.
352
<sel>substituteEntites:</sel>
353
<arg type="BOOL">yesno</arg>
356
Set and return the previous value for entity support.
357
Initially the parser always keeps entity references instead
358
of substituting entity values in the output.
364
<sel>keepBlanks:</sel>
365
<arg type="BOOL">yesno</arg>
368
Set and return the previous value for blank text nodes support.
369
ignorableWhitespace() are only generated when running
370
the parser in validating mode and when the current element
371
doesn't allow CDATA or mixed content.
377
<sel>getWarnings:</sel>
378
<arg type="BOOL">yesno</arg>
384
<sel>doValidityChecking:</sel>
385
<arg type="BOOL">yesno</arg>
388
Sets whether the document needs to be validated.
397
Return error code for last parse operation.