views:

211

answers:

2
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    xmlParseChunk(context, (const char *)[data bytes], [data length], 0);
}

my Question is as follows

=> didReceiveData: method receives data in parts

Some what like this

  • first data----------| <masterData>Main</ma
  • second data-----| ster><masterData>Main2
  • third data --------| </masterData>

=> How xmlParseChunk() method can parse all these chunks successfully?

A: 

One approach is to have your delegate contain an NSMutableData member and invoke appendData: when you get new data. Then parse it when your delegate gets the connectionDidFinishLoading message.

nall
This would be functionally no different than parsing once the entire document is loaded in memory, which defeats the purpose of parsing in chunks.
Alex Reynolds
+1  A: 

Apple's XMLPerformance sample app illustrates a complete implementation of libxml2 integrated with NSURLConnection and chunk parsing. I found it very helpful.

Ole Begemann
sugar
I am not sure what your question is. xmlParseChunk is implemented in the libxml2 library. With every chunk of XML data you pass to it, it can continue parsing a bit further. Presumably, if xmlParseChunk encounters an imcomplete XML tag such as in your example, it just stops parsing until you pass it more data. I guess it uses the xmlParserCtx pointer to maintain its state.
Ole Begemann
Oke ! that's great. that's what I didn't understood.
sugar