-1

I am using NSoperation in Initiating request to server.Pullparser will be called and it will initiate a o/p & i/p stream.In connecitonDidRecievedata I am writing data coming from server to oStream.Imeediately I have to call custom method instead of letting the parser start parsing.How to handle this case.How to handle the ostream call to parser and handle my custom method first then in my custom method I have to call the parser.

- (void)run
{     
    [gObjAppDelegatePtr displayActivityIndicator];
    self.m_cObjDownloadOprPtr = [[[NSInvocationOperation alloc]initWithTarget:self selector:@selector(requestToServer) object:nil]autorelease];

    if((NSOperationQueue *)nil == m_cObjDownloadOprQueuePtr)
    {
         m_cObjDownloadOprQueuePtr = [[NSOperationQueue alloc]init];
         [m_cObjDownloadOprQueuePtr setMaxConcurrentOperationCount:1];
    }
    [m_cObjDownloadOprQueuePtr addOperation:self.m_cObjDownloadOprPtr];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    //[self.m_cWebData setLength: 0];
    [self.m_cWebData appendData:data];    
    [self.m_cObjOriginalWebDataPtr appendData:data];
    [self attemptToWriteToStream];
}

- (void)attemptToWriteToStream 
{
    if([self.m_cWebData length] > 0) 
    {
        [self saveDownloadedData];
        NSUInteger written = [oStream write:(const uint8_t *)[m_cWebData bytes] maxLength:[m_cWebData length]];
        // NSLog(@"Rcvd Data=%d written = %d",[m_cWebData length],written);
        [m_cWebData replaceBytesInRange:NSMakeRange(0,written) withBytes:"" length:0];
        // NSLog(@"Rcvd Data after Reset =%d ",[m_cWebData length]);[self parseResponse];
    }
}

 self.m_cObjSAXHandler = [self createParser:(id)self];
 self.m_cCurrentDownloadInfo = pObjEntry;self.m_cObjConfig = (MobileCRMConfiguration*)super.m_cObjParent.m_cObjConfiguration;
 m_cIsSuccess = NO;

 self.m_cIsOrganizationMatches = NO;
 [self.m_cObjXmlParser ParseWithStream:iStream];

-(void)ParseWithStream:(NSInputStream *)pInputStream
{
    self.m_cObjXMLParser = [[NSXMLParser alloc] initWithStream:pInputStream];
    self.m_cObjXMLParser setDelegate:m_cObjSAXHandler];
    dispatch_block_t dispatch_block  = ^(void){
        [self.m_cObjXMLParser parse];
    };

    dispatch_queue_t dispatch_queue = dispatch_queue_create("parser.queue", NULL);
    dispatch_async(dispatch_queue, dispatch_block);
    dispatch_release(dispatch_queue);
}
  • Sorry I have added the code but my edit is not accpeted by stack overflow. – user2031994 Feb 01 '13 at 10:14
  • You need to format your question properly or hardly anyone will even consider answering it. – Fabian Kreiser Feb 01 '13 at 10:38
  • anyone try to format/edit the question – user2031994 Feb 01 '13 at 11:37
  • I've tried......not sure if it's suppose to look like that! – Gwynant Jones Feb 01 '13 at 11:43
  • Why are you creating a dispatch queue for every time you need to parse a stream? And it looks like you're already within an NSOperation so why would you want to start another thread just for parsing xml when you'r already on a background thread? – Gwynant Jones Feb 01 '13 at 11:48
  • 1
    It seems like you're trying to feed data from an NSURLConnection in to an NSXMLParser in a streaming fashion. Take a look at the answer on http://stackoverflow.com/questions/13740132/streaming-nsxmlparser-with-nsinputstream/14541076#14541076 for some code that achieves that. – bdash Feb 01 '13 at 11:49
  • If I parser the stream using dispatch_queue() and initiate server request with NSOperation then i can handle multiple server requests. – user2031994 Feb 04 '13 at 06:08

1 Answers1

0

I have done this pullparser thing.I have to handle the parser delegates and stream data should be updated when it finished parsing and write the leftover data to stream.