• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSXMLParser and NSXMLDocument mortal enemies
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSXMLParser and NSXMLDocument mortal enemies


  • Subject: NSXMLParser and NSXMLDocument mortal enemies
  • From: Jim Rankin <email@hidden>
  • Date: Sat, 7 Jan 2006 23:47:49 -0500

Has anyone else seen the following?

If I provide a delegate to an NSXMLParser that responds to the error
handling delegate method, the callback sticks around and is called
again if I then try to parse an ill-formed NSXMLDocument later.  The
following code demonstrates this:

#import <Foundation/Foundation.h>

@interface MyParser : NSObject {

}

@end

@implementation MyParser

- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
    NSLog(@"The error is %@", parseError);
}

@end

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    NSXMLDocument *doc;
    NSError *err = nil;

    NSData *data = [@"<foo>" dataUsingEncoding:NSUTF8StringEncoding];

    NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
    [parser setDelegate:[[[MyParser alloc] init] autorelease]];
    [parser parse];
    // [parser setDelegate:nil];

    doc = [[NSXMLDocument alloc] initWithData:data
                                      options:NSXMLNodePreserveAll
                                        error:&err];



    [pool release];
    return 0;
}

The output is:

2006-01-07 23:39:38.918 NSXMLSucks[2692] The error is NSError "Error
NSXMLParserErrorDomain 5" Domain=NSXMLParserErrorDomain Code=5
2006-01-07 23:39:38.924 NSXMLSucks[2692] The error is NSError "Error
NSXMLParserErrorDomain 5" Domain=NSXMLParserErrorDomain Code=5

This seems to be due to both NSXMLParser and NSXMLDocument parsing
being built on the xmlTextReader from libxml, but it's anyone's guess
how the error handler callback is getting registered and how one might
manually unregister it before something else is parsed.   (If you
uncomment // [parser setDelegate:nil]; in the above code the error
message only appears once, but in more complex code I've found even
that is not always sufficient.)

Has anyone else seen this?  Can any libxml gurus suggest a workaround
while I bugreporter this and wait for the fix?

Thanks!

 -jimbo
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Cocoa Bindings and @distinctUnionOfSets
  • Next by Date: Radix Class, A Request for Advice
  • Previous by thread: Re: WebView and NSTabView
  • Next by thread: Radix Class, A Request for Advice
  • Index(es):
    • Date
    • Thread