[Previous] [Up] [Next]

GSXMLParser

Authors

Michael Pakhantsov
Richard Frith-Macdonald

Version: 0.1

Date: 15 September, 2000

GSXMLParser

GSXMLParser

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.

Instance Variables

Methods


Class Methods

parser:

+ (GSXMLParser*) parser: (id)source;

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).

example

  GSXMLParser       *p = [GSXMLParser parser: @"macos.xml"];

  if ([p parse])
    {
      [[p doc] dump];
    }
  else
    {
      printf("error parse file\n");
    }

            

parserWithSAXHandler:source:

+ (GSXMlParser*) parserWithSAXHandler: (GSSAXHandler*)handler source: (id)source;

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.

example

  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];
            

xmlEncodingStringForStringEncoding:

+ (NSString*) xmlEncodingStringForStringEncoding: (NSStringEncoding)encoding;
Return the name of the string encoding (for XML) to use for the specified OpenStep encoding.

Instances Methods

initWithSAXHandler:source:

This is the designated initialiser
- (id) initWithSAXHandler: (GSSAXHandler*)handler source: (id)source;

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.


lib

- (void*) lib;

Return pointer to xmlParserCtxt structure.


doc

- (GSXMLDocument*) doc;

Return GSXMLDocument object.


parse

- (BOOL) parse;

Parse source. Return YES if parsed, otherwise NO. This method should be called once to parse the entiore document.

example

  GSXMLParser       *p = [GSXMLParser parser:@"macos.xml"];

  if ([p parse])
    {
      [[p doc] dump];
    }
  else
    {
      printf("error parse file\n");
    }

            

parse:

- (BOOL) parse: (NSData*)data;

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.

example

  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.

            

substituteEntites:

- (BOOL) substituteEntites: (BOOL)yesno;

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.


keepBlanks:

- (BOOL) keepBlanks: (BOOL)yesno;

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.


getWarnings:

- (BOOL) getWarnings: (BOOL)yesno;

doValidityChecking:

- (BOOL) doValidityChecking: (BOOL)yesno;

Sets whether the document needs to be validated.


errNo

- (int) errNo;

Return error code.


setExternalEntityLoader

- (void) setExternalEntityLoader (void*)function;

Set a external entity loader.