Re: NSXMLParser Error 27 and Crash
Re: NSXMLParser Error 27 and Crash
- Subject: Re: NSXMLParser Error 27 and Crash
- From: John Stiles <email@hidden>
- Date: Sun, 2 Dec 2007 16:24:57 -0800
I'd guess that your file encoding isn't UTF8, so the © character is
throwing the parser out of whack.
On Dec 2, 2007, at 2:53 PM, Eric Russell Balch wrote:
Ok, I'm going to assume that since nobody ever responded to this
that nobody had anything helpful to say ;-) Maybe this added new
info will help someone help me --
I started looking at this again today and realized that what I
reported was only the first of 3 errors that are generated by the
parser and only after the 3rd error and subsequent return from
parseErrorOccurred: does the app actually crash -- the error dialog
had been masking the error. I switch to NSLog() to avoid this.
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)
parseError
{
NSLog(@"Error %i, Description: %@, Line: %i, Column: %i",
[parseError code], [[parser parserError] localizedDescription],
[parser lineNumber], [parser columnNumber]);
}
So I guess the parser keeps going even on error -- Here's what I
see logged now:
12/2/07 2:06:07 PM LC[6561] Error 27, Description: (null), Line:
116, Column: 56
12/2/07 2:06:07 PM LC[6561] Error 27, Description: (null), Line:
116, Column: 66
12/2/07 2:06:07 PM LC[6561] Error 9, Description: (null), Line:
124, Column: 103
Error 9 seems to be:
NSXMLParserInvalidCharacterError - Invalid character encountered.
Line 124 doesn't have 103 columns -- odd. Not even sure if the R/C
numbers line up where I think. Is newline included?
Line 124 to the end of the HTML I'm testing on looks like this:
<p>© 2004-2005 HaX-Revolution, Ltd.</p>
</div>
</div>
</body>
</html>
I haven't made any other important observations or changes since.
Maybe someone else can help who's using NSXMLParser?
Thanks.
On Jul 1, 2007, at 2:43 AM, Eric Balch wrote:
Ok, I'm stumped!
I'm using NSXMLParser for the first time and things have been
progressing nicely until I ran into the following:
The parser returns an error code of 27 which has no description --
the documented errors jump from 26 to 28 -- then the app crashes.
I'm using the parser to parse some HTML in this case and the line
it's barfing on is...
<li><a href="index.html">Home</a> > </li>
...right at the beginning of the second " ". It really
doesn't what I do to this line of HTML though, the parser always
reports the same error at the same position. Very odd.
I'm assuming this has something to do with the crash. I just have
no clue as to what is going wrong.
To start things off I do this:
- (void)parseURL:(id)url
{
BOOL success;
NSURL *xmlURL = [NSURL URLWithString: url];
if (myParser)
[myParser release];
myParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[myParser setDelegate:self];
[myParser setShouldResolveExternalEntities:NO];
success = [myParser parse]; // return value not used
// if not
successful, delegate is informed of error
}
And my parser implements:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)
elementName namespaceURI:(NSString *)namespaceURI qualifiedName:
(NSString *)qName attributes:(NSDictionary *)attributeDict
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)
string
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)
elementName namespaceURI:(NSString *)namespaceURI qualifiedName:
(NSString *)qName
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)
parseError
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
40blizzard.com
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden