Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Is NSXMLParser really a streaming parser?



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.