Version: 0.1
Date: 15 September, 2000
Declared in: GSXML.h
Inherits from: NSObject
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.
Creation of a new Parser by calling initWithSAXHandler:source:
Source must be NSString
(file name),
NSData
(raw document contnets),
NSURL
(not yet implemented),
or nil
(for incremental parsing).
GSXMLParser *p = [GSXMLParser parser: @"macos.xml"]; if ([p parse]) { [[p doc] dump]; } else { printf("error parse file\n"); }
Creation of a new Parser by calling initWithSAXHandler:source:
Source must be NSString
(file name),
NSData
(raw document contnets),
NSURL
(not yet implemented),
or nil
(for incremental parsing).
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.
exampleNSAutoreleasePool *arp = [[NSAutoreleasePool alloc] init]; GSSAXHandler *h = [GSDebugSAXHandler handler]; GSXMLParser *p = [GSXMLParser parserWithSAXHandler: h source: @"macos.xml"]; if ([p parse]) { printf("ok\n"); } [arp release];
Initialisation of a new Parser with SAX handler (if not nil).
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.
In the future, it is intended that this method will also support NSYRL objects.
If the source object is nil
then the parser will
be initialised for incremental parsing.
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.
Return pointer to xmlParserCtxt structure.
Return GSXMLDocument object.
Parse source. Return YES if parsed, otherwise NO. This method should be called once to parse the entiore document.
exampleGSXMLParser *p = [GSXMLParser parser:@"macos.xml"]; if ([p parse]) { [[p doc] dump]; } else { printf("error parse file\n"); }
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.
exampleGSXMLParser *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.
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.
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.
Sets whether the document needs to be validated.
Return error code.
Set a external entity loader.