-1

サーバーへの要求の開始で NSoperation を使用しています。Pullparser が呼び出され、ao/p & i/p ストリームが開始されます。connecitonDidRecievedata では、サーバーからのデータを oStream に書き込みます。パーサーは解析を開始します。このケースの処理方法。パーサーへの ostream 呼び出しを処理し、最初にカスタム メソッドを処理する方法、次にカスタム メソッドでパーサーを呼び出す必要があります。

- (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);
}
4

1 に答える 1

0

パーサー デリゲートを処理する必要があり、解析が終了したらストリーム データを更新し、残りのデータをストリームに書き込む必要があります。

于 2013-02-05T11:20:37.120 に答える