Re: Is NSXMLParser really a streaming parser?
Re: Is NSXMLParser really a streaming parser?
- Subject: Re: Is NSXMLParser really a streaming parser?
- From: Christopher Woodruff <email@hidden>
- Date: Thu, 1 Nov 2007 13:49:22 -0700
Thanks for the help. Do you know of any third party xml parsers that
might work in this fashion? I've found a number of people that talk
about expat with the objective-c wrapper. Is this a possible
solution, or is it limited in the same way?
Chris Woodruff
Jet Propulsion Laboratory
M/S: 138-206
4800 Oak Grove Dr.
Pasadena, CA 91109
818-354-2412
On Nov 1, 2007, at 1:28 PM, Chris Parker wrote:
Hi Christopher,
I think you're misunderstanding the use of the word "streaming" in
the API description. NSXMLParser is a "streaming" parser in the
sense that it produces a stream of events w.r.t. the XML document
rather than a fully-cooked document/DOM tree.
We have an enhancement request for NSXMLParser to accept an
NSInputStream, which would do the kind of thing you're trying to do
here. Unfortunately as of Leopard there is still no "take bytes in
chunks and parse them" API on NSXMLParser.
BTW, your code below is re-initializing the same parser instance
over and over again - you should only be sending any "-init*"
method to an object instance once. The behavior you'd be getting
here is completely undefined.
.chris
--
Chris Parker
Cocoa Frameworks
Apple Inc.
On Nov 1, 2007, at 11:29 AM, Christopher Woodruff wrote:
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
_______________________________________________
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