Is NSXMLParser really a streaming parser?
Is NSXMLParser really a streaming parser?
- Subject: Is NSXMLParser really a streaming parser?
- From: Christopher Woodruff <email@hidden>
- Date: Thu, 1 Nov 2007 11:29:33 -0700
I am working on a project that requires parsing of XML data that
comes from a socket stream. I want to feed an NSXMLParser object xml
data from my socket connection 1 byte at a time. Is this possible?
So far I have been receiving the socket stream data from a
NSFileHandle. I subscribe an object to receive the
NSFileHandleReadCompletionNotification and get the NSData item from
the notification. Then I initialize the XMLParser with the NSData.
Will the NSXMLParser be able to parse correctly if I give it xml data
1 byte at a time? This might mean that the data I feed the
XMLParser is cut in the middle of a tag or the contents.
- (void)xmlStream:(NSNotification *)notification
{
NSData *messageData = [[notification userInfo]
objectForKey:NSFileHandleNotificationDataItem];
if ( [messageData length] == 0 ) {
[xmlFileHandle readInBackgroundAndNotify];
return;
}
if(!xmlController)
{
xmlController = [[XMLcontroller alloc] init];
}
[xmlController initXMLparser: messageData];
[xmlController startParse];
[xmlFileHandle readInBackgroundAndNotify];
}
Inside my xml controller object
- (void) initXMLparser:(NSData *) xmlData
{
if(!parser)
{
parser = [[NSXMLParser alloc] initWithData: xmlData];
[parser setDelegate: self];
[parser setShouldResolveExternalEntities:YES];
}
[parser initWithData: xmlData];
nc = [NSNotificationCenter defaultCenter];
}
- (void) startParse
{
[parser parse];
}
Any insights will be greatly appreciated.
Chris Woodruff
Jet Propulsion Laboratory
M/S: 138-206
4800 Oak Grove Dr.
Pasadena, CA 91109
818-354-2412
_______________________________________________
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