2000-09-15 19:56:39 +00:00
|
|
|
<html><head>
|
|
|
|
<title>GSXMLParser</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<a href="GSXMLAttribute.html">[Previous]</a>
|
|
|
|
<a href="GSXML.html">[Up]</a>
|
|
|
|
<a href="GSSAXHandler.html">[Next]</a>
|
|
|
|
<h1>GSXMLParser</h1>
|
|
|
|
<h3>Authors</h3>
|
|
|
|
<dl>
|
|
|
|
<dt>Michael Pakhantsov
|
|
|
|
<dd>
|
|
|
|
<dt>Richard Frith-Macdonald
|
|
|
|
<dd>
|
|
|
|
</dl>
|
|
|
|
<p>Version: 0.1</p>
|
|
|
|
<p>Date: 15 September, 2000</p>
|
|
|
|
<h2><a name="cont-0">GSXMLParser</a></h2>
|
|
|
|
<h2><a name="GSXMLParser">GSXMLParser</a></h2>
|
|
|
|
<p><b>Declared in:</b> GSXML.h</p>
|
2000-09-20 06:45:02 +00:00
|
|
|
<p><b>Inherits from:</b> NSObject</p>
|
2000-09-15 19:56:39 +00:00
|
|
|
<hr>
|
|
|
|
|
2000-09-20 06:45:02 +00:00
|
|
|
<p>
|
|
|
|
|
|
|
|
The XML parser object is the pivotal part of parsing an XML
|
|
|
|
document - it will either build a tree representing the
|
|
|
|
document, or will cooperate with a GSSAXHandler object to
|
|
|
|
provide parsing without the overhead of building a tree.
|
|
|
|
</p>
|
2000-09-15 19:56:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
<h2>Instance Variables</h2>
|
|
|
|
<ul>
|
|
|
|
</ul>
|
|
|
|
<h2>Methods</h2>
|
|
|
|
<ul>
|
|
|
|
<li><a href="GSXMLParser.html#method-0">+parser:</a>
|
|
|
|
<li><a href="GSXMLParser.html#method-2">+parserWithSAXHandler:source:</a>
|
2000-09-19 20:47:56 +00:00
|
|
|
<li><a href="GSXMLParser.html#method-4">+xmlEncodingStringForStringEncoding:</a>
|
2000-09-20 06:45:02 +00:00
|
|
|
<li><a href="GSXMLParser.html#method-15">-doValidityChecking:</a>
|
2000-09-19 20:47:56 +00:00
|
|
|
<li><a href="GSXMLParser.html#method-7">-doc</a>
|
2000-09-20 06:45:02 +00:00
|
|
|
<li><a href="GSXMLParser.html#method-16">-errNo</a>
|
|
|
|
<li><a href="GSXMLParser.html#method-14">-getWarnings:</a>
|
2000-09-19 20:47:56 +00:00
|
|
|
<li><a href="GSXMLParser.html#method-5">-initWithSAXHandler:source:</a>
|
2000-09-20 06:45:02 +00:00
|
|
|
<li><a href="GSXMLParser.html#method-13">-keepBlanks:</a>
|
2000-09-19 20:47:56 +00:00
|
|
|
<li><a href="GSXMLParser.html#method-6">-lib</a>
|
|
|
|
<li><a href="GSXMLParser.html#method-8">-parse</a>
|
2000-09-20 06:45:02 +00:00
|
|
|
<li><a href="GSXMLParser.html#method-10">-parse:</a>
|
|
|
|
<li><a href="GSXMLParser.html#method-17">-setExternalEntityLoader</a>
|
|
|
|
<li><a href="GSXMLParser.html#method-12">-substituteEntites:</a>
|
2000-09-15 19:56:39 +00:00
|
|
|
</ul>
|
|
|
|
<hr><h2>Class Methods</h2>
|
|
|
|
<h3><a name="method-0">parser:</a></h3>
|
|
|
|
+ (<A HREF="GSXMLParser.html#GSXMLParser">GSXMLParser</A>*) <b>parser:</b> (id)source;<br>
|
|
|
|
|
|
|
|
<p>
|
2000-09-19 20:47:56 +00:00
|
|
|
Creation of a new Parser by calling initWithSAXHandler:source:
|
2000-09-15 19:56:39 +00:00
|
|
|
</p>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
2000-09-20 06:45:02 +00:00
|
|
|
Source must be <code>NSString</code> (file name),
|
|
|
|
<code>NSData</code> (raw document contnets),
|
|
|
|
<code>NSURL</code> (not yet implemented),
|
|
|
|
or <code>nil</code> (for incremental parsing).
|
2000-09-15 19:56:39 +00:00
|
|
|
</p>
|
|
|
|
|
|
|
|
<a name="label-1">example</a>
|
|
|
|
<pre>
|
|
|
|
|
2000-09-20 06:45:02 +00:00
|
|
|
GSXMLParser *p = [GSXMLParser parser: @"macos.xml"];
|
2000-09-15 19:56:39 +00:00
|
|
|
|
|
|
|
if ([p parse])
|
|
|
|
{
|
|
|
|
[[p doc] dump];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("error parse file\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<hr>
|
|
|
|
<h3><a name="method-2">parserWithSAXHandler:source:</a></h3>
|
2000-09-20 06:45:02 +00:00
|
|
|
+ (GSXMlParser*) <b>parserWithSAXHandler:</b> (GSSAXHandler*)handler <b>source:</b> (id)source;<br>
|
2000-09-15 19:56:39 +00:00
|
|
|
|
|
|
|
<p>
|
2000-09-20 06:45:02 +00:00
|
|
|
|
|
|
|
Creation of a new Parser by calling initWithSAXHandler:source:
|
2000-09-15 19:56:39 +00:00
|
|
|
</p>
|
|
|
|
|
2000-09-20 06:45:02 +00:00
|
|
|
<p>
|
|
|
|
|
|
|
|
Source must be <code>NSString</code> (file name),
|
|
|
|
<code>NSData</code> (raw document contnets),
|
|
|
|
<code>NSURL</code> (not yet implemented),
|
|
|
|
or <code>nil</code> (for incremental parsing).
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
|
|
|
If the handler object supplied is nil, the parser will build
|
|
|
|
a tree representing the parsed file rather than attempting
|
|
|
|
to get the handler to deal with the parsed elements and entities.
|
|
|
|
</p>
|
|
|
|
|
2000-09-15 19:56:39 +00:00
|
|
|
<a name="label-3">example</a>
|
|
|
|
<pre>
|
|
|
|
|
|
|
|
NSAutoreleasePool *arp = [[NSAutoreleasePool alloc] init];
|
|
|
|
GSSAXHandler *h = [GSDebugSAXHandler handler];
|
|
|
|
GSXMLParser *p = [GSXMLParser parserWithSAXHandler: h
|
|
|
|
source: @"macos.xml"];
|
|
|
|
|
|
|
|
if ([p parse])
|
|
|
|
{
|
|
|
|
printf("ok\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[arp release];
|
|
|
|
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
2000-09-19 20:47:56 +00:00
|
|
|
<hr>
|
|
|
|
<h3><a name="method-4">xmlEncodingStringForStringEncoding:</a></h3>
|
2000-09-20 06:45:02 +00:00
|
|
|
+ (NSString*) <b>xmlEncodingStringForStringEncoding:</b> (NSStringEncoding)encoding;<br>
|
2000-09-19 20:47:56 +00:00
|
|
|
|
|
|
|
Return the name of the string encoding (for XML) to use for the
|
|
|
|
specified OpenStep encoding.
|
|
|
|
|
2000-09-15 19:56:39 +00:00
|
|
|
<hr>
|
|
|
|
<hr><h2>Instances Methods</h2>
|
2000-09-19 20:47:56 +00:00
|
|
|
<h3><a name="method-5">initWithSAXHandler:source:</a></h3>
|
2000-09-15 19:56:39 +00:00
|
|
|
<b>This is the designated initialiser</b><br>
|
2000-09-20 06:45:02 +00:00
|
|
|
- (id) <b>initWithSAXHandler:</b> (GSSAXHandler*)handler <b>source:</b> (id)source;<br>
|
2000-09-15 19:56:39 +00:00
|
|
|
|
2000-09-19 20:47:56 +00:00
|
|
|
<p>
|
|
|
|
|
|
|
|
Initialisation of a new Parser with SAX handler (if not nil).
|
2000-09-15 19:56:39 +00:00
|
|
|
</p>
|
|
|
|
|
2000-09-19 20:47:56 +00:00
|
|
|
<p>
|
|
|
|
|
|
|
|
The source object is intended to be any reasonable value,
|
|
|
|
but for initial implementation may be an NSData object
|
|
|
|
containing raw XML text, or the name of a file to parse.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
2000-09-20 06:45:02 +00:00
|
|
|
In the future, it is intended that this method will also
|
|
|
|
support NSYRL objects.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
|
|
|
If the source object is <code>nil</code> then the parser will
|
|
|
|
be initialised for incremental parsing.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
|
|
|
If the handler object supplied is nil, the parser will build
|
|
|
|
a tree representing the parsed file rather than attempting
|
|
|
|
to get the handler to deal with the parsed elements and entities.
|
2000-09-19 20:47:56 +00:00
|
|
|
</p>
|
|
|
|
|
2000-09-15 19:56:39 +00:00
|
|
|
|
|
|
|
<hr>
|
2000-09-19 20:47:56 +00:00
|
|
|
<h3><a name="method-6">lib</a></h3>
|
2000-09-15 19:56:39 +00:00
|
|
|
- (void*) <b>lib</b>;<br>
|
|
|
|
|
2000-09-20 06:45:02 +00:00
|
|
|
<p>
|
2000-09-15 19:56:39 +00:00
|
|
|
Return pointer to xmlParserCtxt structure.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
<hr>
|
2000-09-19 20:47:56 +00:00
|
|
|
<h3><a name="method-7">doc</a></h3>
|
2000-09-20 06:45:02 +00:00
|
|
|
- (GSXMLDocument*) <b>doc</b>;<br>
|
2000-09-15 19:56:39 +00:00
|
|
|
|
2000-09-20 06:45:02 +00:00
|
|
|
<p>
|
2000-09-15 19:56:39 +00:00
|
|
|
Return GSXMLDocument object.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
<hr>
|
2000-09-19 20:47:56 +00:00
|
|
|
<h3><a name="method-8">parse</a></h3>
|
2000-09-15 19:56:39 +00:00
|
|
|
- (BOOL) <b>parse</b>;<br>
|
|
|
|
|
2000-09-20 06:45:02 +00:00
|
|
|
<p>
|
|
|
|
|
|
|
|
Parse source. Return YES if parsed, otherwise NO.
|
|
|
|
This method should be called once to parse the entiore document.
|
2000-09-15 19:56:39 +00:00
|
|
|
</p>
|
|
|
|
|
2000-09-19 20:47:56 +00:00
|
|
|
<a name="label-9">example</a>
|
2000-09-15 19:56:39 +00:00
|
|
|
<pre>
|
|
|
|
|
|
|
|
GSXMLParser *p = [GSXMLParser parser:@"macos.xml"];
|
|
|
|
|
|
|
|
if ([p parse])
|
|
|
|
{
|
|
|
|
[[p doc] dump];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("error parse file\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
|
|
<hr>
|
2000-09-20 06:45:02 +00:00
|
|
|
<h3><a name="method-10">parse:</a></h3>
|
|
|
|
- (BOOL) <b>parse:</b> (NSData*)data;<br>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
|
|
|
Pass data to the parser for incremental parsing. This method
|
|
|
|
should be called many times, with each call passing another
|
|
|
|
block of data from the same document. After the whole of the
|
|
|
|
document has been parsed, the method should be called with
|
|
|
|
an empty or nil data object to indicate end of parsing.
|
|
|
|
Once this has been done, the method may be used again to
|
|
|
|
parse a new document.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<a name="label-11">example</a>
|
|
|
|
<pre>
|
|
|
|
|
|
|
|
GSXMLParser *p = [GSXMLParser parserWithSAXHandler: nil source: nil];
|
|
|
|
|
|
|
|
while ((data = getMoreData()) != nil)
|
|
|
|
{
|
|
|
|
if ([p parse: data] == NO)
|
|
|
|
{
|
|
|
|
NSLog(@"parse error");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Do something with document parsed
|
|
|
|
|
|
|
|
[p parse: nil]; // Ready to parse another document.
|
|
|
|
|
|
|
|
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
|
|
<hr>
|
|
|
|
<h3><a name="method-12">substituteEntites:</a></h3>
|
2000-09-15 19:56:39 +00:00
|
|
|
- (BOOL) <b>substituteEntites:</b> (BOOL)yesno;<br>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
Set and return the previous value for default entity support.
|
|
|
|
Initially the parser always keep entity references instead of substituting
|
|
|
|
entity values in the output.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
<hr>
|
2000-09-20 06:45:02 +00:00
|
|
|
<h3><a name="method-13">keepBlanks:</a></h3>
|
2000-09-15 19:56:39 +00:00
|
|
|
- (BOOL) <b>keepBlanks:</b> (BOOL)yesno;<br>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
Set and return the previous value for default blanks text nodes support.
|
|
|
|
ignorableWhitespace() are only generated when running the parser in validating mode
|
|
|
|
and when the current element doesn't allow CDATA or mixed content.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
<hr>
|
2000-09-20 06:45:02 +00:00
|
|
|
<h3><a name="method-14">getWarnings:</a></h3>
|
2000-09-15 19:56:39 +00:00
|
|
|
- (BOOL) <b>getWarnings:</b> (BOOL)yesno;<br>
|
|
|
|
|
|
|
|
|
|
|
|
<hr>
|
2000-09-20 06:45:02 +00:00
|
|
|
<h3><a name="method-15">doValidityChecking:</a></h3>
|
2000-09-15 19:56:39 +00:00
|
|
|
- (BOOL) <b>doValidityChecking:</b> (BOOL)yesno;<br>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
Sets whether the document needs to be validated.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
<hr>
|
2000-09-20 06:45:02 +00:00
|
|
|
<h3><a name="method-16">errNo</a></h3>
|
2000-09-15 19:56:39 +00:00
|
|
|
- (int) <b>errNo</b>;<br>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
Return error code.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
<hr>
|
2000-09-20 06:45:02 +00:00
|
|
|
<h3><a name="method-17">setExternalEntityLoader</a></h3>
|
2000-09-15 19:56:39 +00:00
|
|
|
- (void) <b>setExternalEntityLoader</b> (void*)function;<br>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
Set a external entity loader.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
<hr>
|
|
|
|
</body>
|
|
|
|
|
|
|
|
</html>
|