Parsing and inserting data into SQLITE - ios - ios

In my iPAD application, I call a webservice to get a XML response, then I parse it and store it into my SQLITE database.
The parsing and saving are happening properly, but the problem I am having is that it is taking a very long time for it to perform the operation.
Using the mac, I saw the number of records being saved to the database. It was 395 rows where each row has 8 columns in it i.e. around 3100 records are being stored to my database.(my entity has 8 attributes in it). On the iPAD, it takes about 25 seconds to do the whole operation, which I was told is too long.
I am unable to figure out why it is taking so long and where I am going wrong.
This is the code which I use for parsing the XML and storing -
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqualToString:#"return"])
{
// Blank lab panel object
objLabPanel = [NSEntityDescription insertNewObjectForEntityForName:#"LabPanels" inManagedObjectContext:managedObjectContext];
mainElement = elementName;
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
elementValue = [[NSMutableString alloc] init];
[elementValue appendString:string];
// Handle html codes
elementValue = [CommonHelper encodeHTMLCharactorsForDataBaseStorage:elementValue];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:#"return"])
{
[objPatient addLabPanelsObject:objLabPanel];
// Save
NSError *error = nil;
BOOL saveObj = FALSE;
saveObj = [managedObjectContext save:&error];
if (saveObj == FALSE)
{
NSLog (#"Error: %#", error);
}
}
else if ([elementName isEqualToString:#"batteryID"] && [mainElement isEqualToString:#"return"])
{
objLabPanel.labPanelBatteryId = elementValue;
}
else if ([elementName isEqualToString:#"batteryVersionNum"] && [mainElement isEqualToString:#"return"])
{
objLabPanel.labBatteryVersionId = elementValue;
}
else if ([elementName isEqualToString:#"conceptCode"] && [mainElement isEqualToString:#"return"])
{
objLabPanel.labPanelCode = elementValue;
}
else if ([elementName isEqualToString:#"conceptDescription"] && [mainElement isEqualToString:#"return"])
{
objLabPanel.labPanelDesc = elementValue;
}
else if ([elementName isEqualToString:#"effectiveEndTime"] && [mainElement isEqualToString:#"return"])
{
endDate = [CommonHelper getDateFromXMLString:[NSString stringWithString:elementValue] :#"yyyy-MM-dd'T'HHmmssZ"];
objLabPanel.labPanelEndDate = endDate;
}
else if ([elementName isEqualToString:#"effectiveStartTime"] && [mainElement isEqualToString:#"return"])
{
startDate = [CommonHelper getDateFromXMLString:[NSString stringWithString:elementValue] :#"yyyy-MM-dd'T'HHmmssZ"];
objLabPanel.labPanelStartDate = startDate;
}
else if ([elementName isEqualToString:#"body"])
{
// Release all variables at the end of xml parsing
[self releaseVariables];
}
elementValue = nil;
}
Here is a sample of the XML I am parsing -
<return>
<batteryID>1234</batteryID>
<batteryVersionNum>1</batteryVersionNum>
<conceptCode>abc</conceptCode>
<conceptDescription>abc</conceptDescription>
<effectiveEndTime>2010-11-23</effectiveEndTime>
<effectiveStartTime>2010-11-23</effectiveStartTime>
</return>
<return>
<batteryID>2345</batteryID>
<batteryVersionNum>1</batteryVersionNum>
<conceptCode>bac</conceptCode>
<conceptDescription>bac</conceptDescription>
<effectiveEndTime>2010-11-23</effectiveEndTime>
<effectiveStartTime>2010-11-23</effectiveStartTime>
</return>
It would be great if someone could help me out with this and tell me if something is wrong with the way I am parsing and saving.

You should save the MOC periodically, not for every insert. The MOC is saved when you ask for it to be saved, so it's up to you to determine when that is. Typically you should only save the MOC when it is consistent in terms of your needs (it's always consistent in terms of low-level relationships). I would wait until the end of parsing in any case.

Related

Web Service - Getting data in Xcode

I'm new to this web service in iOS. I made a sample web service app and made the first stage login successfully. While checking the url in web after login I got this output :
<Rows>
<Row>
<style>LW6001TA</style>
<thumbnail1>
/9j/4AAQSkZJRgABAQEAAAAAAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyM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L3jhHmN+fA/nXpXh74UeFfD5WQWX224HIluzvx9F6D8qAPnPQPBviDxFcpHpmnTupIzMy7Y19yx4r600WC8tdEsrfUJI5LuKFUlePO1mAxkZq6kaxqFRQqjoAMAU6gAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACsrxHokXiPQLzSZppIUuU2mSPqvOf6Vq0UAfNWufA/wAT6ezNp/kalDnjy3CPj3Vv6GuVfwD4tRmU+HtQyvXEJP8AKvr+igD4tvtB1fTW232mXluT08yFh/SqXkTZC+VJk9BtNfbrxpIMOisPQjNRfY7YsGNtFuHQ7BkUAfFP2W4HW3l/74NNMEoGTE4+qmvtr7PAf+WMf/fIprWdq4w1tCQexQUAfEm1vQ1IlvPIMxwyOPVVJr7R/sjTf+gfa/8Aflf8Kmis7aBdsVtEi+ioAKAPir7JdAZNtMP+2Z/wqMwTZ/1Un/fJr7cMERH+qT/vkU37Jbf8+8X/AHwKAPiZ7aeNd7wSqvqUIFRV9uyWltNGY5LeJ0PVWQEGsQeA/CgnM3/CPafvJyT5A6/TpQB8eil7V9ReKvhF4c8QWxNnbJpl4v3ZbdAFP+8vQ/zrzCT4DeKFnKpdaeyZ4fzGGR64xQB5Xzmpktrh/uQSsPZCa+lPAnwj0zwygu9UWLUNSP8AEy5jj/3Qep9zXoiWtvGMJBGo9kAoA+LY9K1GVgsdhdOT0Cwsc/pWlH4M8Ty/c0DUT/27t/hX2II0HRFH0FOoA+SrL4Y+M75gI9BuIwf4piIx+pruNB+Ad9Ntk13UY7de8Nt87f8AfR4H6177RQBxmi/Czwhou1otKS4mX/lpdEyH8jx+ldikaRIEjRURRgKowBTqKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD/9k=
</thumbnail1>
</Row>
</Rows>
How to get these stuff back in Xcode and view it ? This is the first time I work on this web service I have no idea to get back this response back in Xcode. Please Help !
-(void)parseTheData
{
//Here convert your response to NSData type (NSData *data = [NSData data]; , i have used just for example)
NSData *data = [NSData data];
// Make sure that there is data.
if (data != nil) {
self.xmlParser = [[NSXMLParser alloc] initWithData:data];
self.xmlParser.delegate = self;
// Initialize the mutable string that we'll use during parsing.
self.foundValue = [[NSMutableString alloc] init];
// Start parsing.
[self.xmlParser parse];
}
}
//Delegate methods
-(void)parserDidStartDocument:(NSXMLParser *)parser{
// Initialize the array.
self.arrNeighboursData = [[NSMutableArray alloc] init];
}
-(void)parserDidEndDocument:(NSXMLParser *)parser{
// When the parsing has been finished then simply reload the table view or do what ever you want
}
-(void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError{
NSLog(#"%#", [parseError localizedDescription]);
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
// If the current element name is equal to "geoname" then initialize the temporary dictionary.
if ([elementName isEqualToString:#"Row"]) {
self.dictTempDataStorage = [[NSMutableDictionary alloc] init];
}
// Keep the current element.
self.currentElement = elementName;
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:#"thumbnail1"]) {
// Store the data like this
[self.dictTempDataStorage setObject:[NSString stringWithString:self.foundValue] forKey:#"thumbnail1"];
}
else if ([elementName isEqualToString:#"style"]){
// Store the data like this
[self.dictTempDataStorage setObject:[NSString stringWithString:self.foundValue] forKey:#"style"];
}
else if ([elementName isEqualToString:#"Row"])
{
//Add the dictionary in array and remove the data from dictionary, so that we can reuse the dictionary
[self.arrNeighboursData addObject:self.dictTempDataStorage];
self.dictTempDataStorage = nil;
}
// Clear the mutable string.
[self.foundValue setString:#""];
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
// Store the found characters if only we're interested in the current element.
if (![string isEqualToString:#"\n"]) {
[self.foundValue appendString:string];
}
}
Here I am just showing you the way to move on.

Parse the Anchor tags and the content using NSXMLParse

I want to parse the html tags inside the "comparison" node
<comparison>
Amazon.com
($34.36) |
Walmart.com
($34.36) |
Rakuten.com
($34.36) |
BestBuy.com
($34.36)
</comparison>
The output I am getting is:
BestBuy.com ($34.36)
The expected output:
Amazon.com ($34.36)
Walmart.com ($34.36)
Rakuten.com ($34.36)
BestBuy.com ($34.36)
But I want to display all the four items.
CODE
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
currentElementValue = [NSMutableString string];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
if ([elementName isEqualToString:#"item"]) {
dealsListObj = [[DealsParsingObjects alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
[currentElementValue appendString:string];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:#"short_title"]) {
dealsListObj.itemTitle = currentElementValue;
currentElementValue = nil;
}
else if ([elementName isEqualToString:#"final_price"]) {
dealsListObj.price = currentElementValue;
currentElementValue = nil;
}
//Detail view
else if ([elementName isEqualToString:#"merchant"]) {
dealsListObj.itemMerchant = currentElementValue;
currentElementValue = nil;
}
else if ([elementName isEqualToString:#"getdeal"]) {
dealsListObj.itemGetDeal = currentElementValue;
currentElementValue = nil;
}
//comparison
else if ([elementName isEqualToString:#"comparison"]) {
dealsListObj.comparison = currentElementValue;
currentElementValue = nil;
}
else if ([elementName isEqualToString:#"item"]) {
[resultArray addObject:dealsListObj];
[dealsListObj release];
dealsListObj = nil;
currentElementValue = nil;
}
}
It appears you have a DealsParsingObjects class with an NSMutableArray called commentsArray. You instantiate that array, when the parsing begins reading the <comparison> element.
But when the parser has read a <comparison> element, you assign the value to a property called comparison; it doesn't get added to the array. Being an default NSString property (assumption on my part), it simply gets reassigned each time the parser is done reading a <comparison> element.
Edit:
parser:didStartElement:... is called every time a new element is read. This also holds for the <a> tags. In that method you reset currentElementValue. So for each <a> the value is basically reset to an empty string. Only the last read value remains, which is the value of the last <a> tag plus the trailing text.

malloc: error for object: double free

I have been trying to debug this error, and I can't find the issue. From what I have researched, I think that this is telling me that I am trying to release an object that has already been real eased, although I am not sure. I have a object that acts as the delegate for a NSXMLParser object, and I have a property of type NSMutableString that I use to hold the characters of each element. Here is my code:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
self.stringBuffer = [NSMutableString string];
if ([elementName isEqualToString:#"item"])
self.parsingPodcast = YES;
if (attributeDict)
self.currentAttributesDict = attributeDict;
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if (string) [self.stringBuffer appendString:string];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if (self.parsingPodcast)
{
if ([elementName isEqualToString:#"title"])
{
self.currentPodcastObject.title = self.stringBuffer;
}
else if ([elementName isEqualToString:#"pubDate"])
{
self.currentPodcastObject.publishDate = self.stringBuffer;
}
else if ([elementName isEqualToString:#"summary"])
{
self.currentPodcastObject.summary = self.stringBuffer;
}
else if ([elementName isEqualToString:#"imageurl"])
{
self.currentPodcastObject.imgURL = self.stringBuffer;
}
else if ([elementName isEqualToString:#"enclosure"])
{
self.currentPodcastObject.audioURL = [self.currentAttributesDict objectForKey:#"url"];
self.currentPodcastObject.audioType = [self.currentAttributesDict objectForKey:#"type"];
}
else if ([elementName isEqualToString:#"itunes:duration"])
{
self.currentPodcastObject.duration = self.stringBuffer;
}
else if ([elementName isEqualToString:#"item"])
{
parserCompletionBlock(self.currentPodcastObject);
}
}
}
I've enabled zombies in the scheme, and used the zombie tool to try and find any over released object, but I haven't been able to find anything. Here is the output on the console
:malloc: *** error for object 0x10e7531f0: double free
*** set a breakpoint in malloc_error_break to debug
I have added the malloc_error_break breakpoint
The breakpoint stops on the setter method for the self.stringBuffer property. Can anyone help me out? I must be missing something. Thanks in advance for your help!
[NSMutableString string] is autorelease. you should retain when assigning it on self.stringBuffer.
self.stringBuffer = [NSMutableString string] retain]
I actually got this error because the memory in my phone was almost full. Once i cleared some apps in my phone, the error went away. Not sure if this is useful, but it definitely helped me.

Why does this not parse correctly?

Ok so basically, I am trying to parse a sub-element:
<element>
<sub element 1>
<sub element 2>
<sub element 3>
<element>
The current original document that I want to parse contain as below for example:
sub-element-content1: AB, CD, DE, & SOMETHING DISPLAYED.
I only managed to grab & SOMETHING DISPLAYED. I could not parse the whole sub-element.
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
currentNodeContent = (NSMutableString *)[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
//NSLog(#"CURRENT CONTENT: %#", currentNodeContent);
}
That is the 1st issue. The second issue that I am having is that there are supposed to be 11 items in reference to the above. But it only managed to grab 2 items. Please note that each item contains the sub-elements except that some sub-elements are null
Issues has been added: (null)-(null)-(null)
Issues has been added: sub-element-1 sub-element2 sub-element3
Below is portion of didEndElement:
if ([elementName isEqualToString:#"Issue"]) {
//add currentIssue object into issues array
[issues addObject:currentIssue];
NSLog(#"Issues has been added: %#-%#-%#", currentIssue.sub-element-1, currentIssue.sub-element-2, currentIssue.sub-element-3);
currentIssue = nil;
currentNodeContent = nil;
}
if ([elementName isEqualToString:#"sub element 1"]) {
currentIssue.sub-element-1 = currentNodeContent;
NSLog(#"sub element 1: %#", currentIssue.sub-element-1);
}
if ([elementName isEqualToString:#"sub element 2"]) {
currentIssue.sub-element-2 = currentNodeContent;
NSLog(#"sub element 2: %#", currentIssue.sub-element-2);
}
if ([elementName isEqualToString:#"sub element 3"]) {
currentIssue.sub-element-3 = currentNodeContent;
NSLog(#"sub element 3: %#", currentIssue.sub-element-3);
}
Your advice(s) and/or suggestion(s) are greatly appreciated.
Update 1:
Ok, I have solved the problem.
It appears that "currentIssue = nil" causes the object to lose its contents as I was able to print out the currentNodeContent.
So, by removing, currentIssue, I am now able to see all the supposed elements that I need.
But there is one more problem. I can see all the sub elements now, but there only one sub element left which was grabbed partially which I do not understand why.
For <sub element 1> , sub element 1 is not the elementName . The element name is sub.
- (XMLParserViewController *) initXMLParser {
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
return self;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict
{
if([elementName isEqualToString:#"Books"]) {
appDelegate.books = [[NSMutableArray alloc] init];
}
else if([elementName isEqualToString:#"Book"])
{
aBook = [[Books alloc] init];
}
NSLog(#"Processing Element: %#", elementName);
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if(!currentElementValue)
currentElementValue = [[NSMutableString alloc] initWithString:string];
else
[currentElementValue appendString:string];
NSLog(#"Processing Value: %#", currentElementValue);
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if([elementName isEqualToString:#"Books"])
return;
if([elementName isEqualToString:#"Book"])
{
[appDelegate.books addObject:aBook];
aBook = nil;
}
else if([elementName isEqualToString:#"name"])
{
aBook.name=currentElementValue;
}
else if([elementName isEqualToString:#"address"])
{
aBook.address=currentElementValue;
}
else if([elementName isEqualToString:#"country"])
{
aBook.country=currentElementValue;
}
currentElementValue = nil;
NSLog(#"%#",aBook.name);
NSLog(#"%#",aBook.address);
NSLog(#"%#",aBook.country);
}
Try this code eith your elements hope this works for you.... :)
Ok, I have solved the problem.
It appears that "currentIssue = nil" causes the object to lose its contents as I was able to print out the currentNodeContent.
So, by removing, currentIssue, I am now able to see all the supposed elements that I need.
Secondly, to make it work correctly, I initialized the array under "parserDidStartDocument" instead of "parserDidStartElement".

IOS: NSMXLParser with multiple node

I have a file xml as this:
<data>
<first>
<city>
city
</city>
<people>
400
</people>
</first>
<size>
<width>
340
</width>
<height>
120
</height>
</size>
<description>
<temp>
sunny
</temp>
<people>
45
</people>
</description>
<description>
<temp>
cloudy
</temp>
<people>
90
</people>
</description>
I use for parsing this code:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
currentElement = [elementName copy];
if ([elementName isEqualToString:#"first"]) {
firstType = [[NSMutableDictionary alloc] init];
currentCity = [[NSMutableString alloc] init];
currentPeople = [[NSMutableString alloc] init];
}
if ([elementName isEqualToString:#"size"]){
currentSize = [[NSMutableDictionary alloc] init];
width = [[NSMutableString alloc]init];
height = [[NSMutableString alloc]init];
}
if ([elementName isEqualToString:#"description"]){
desc1 = [[NSMutableDictionary alloc] init];
temp1 = [[NSMutableString alloc]init];
people1 = [[NSMutableString alloc]init];
}
if ([elementName isEqualToString:#"description"]){
desc2 = [[NSMutableDictionary alloc] init];
temp2 = [[NSMutableString alloc]init];
people2 = [[NSMutableString alloc]init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:#"first"]) {
[firstType setObject:currentType forKey:#"city"];
[firstType setObject:currentQuery forKey:#"people"];
[feed addObject:[firstType copy]];
}
if ([elementName isEqualToString:#"size"]){
[currentSize setObject:tempC forKey:#"width"];
[currentSize setObject:tempF forKey:#"height"];
[feed addObject:[currentSize copy]];
}
if ([elementName isEqualToString:#"description"]){
[desc1 setObject:temp1 forKey:#"temp1"];
[desc1 setObject:people1 forKey:#"people1"];
[feed addObject:[desc1 copy]];
}
if ([elementName isEqualToString:#"description"]){
[desc2 setObject:temp1 forKey:#"temp2"];
[desc2 setObject:people1 forKey:#"people2"];
[feed addObject:[desc2 copy]];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
NSLog(#"found");
if ([currentElement isEqualToString:#"city"]){
[currentCity appendString:string];
}
else if ([currentElement isEqualToString:#"people"]) {
[currentPeople appendString:string];
}
else if ([currentElement isEqualToString:#"width"]){
[width appendString:string];
}
else if ([currentElement isEqualToString:#"height"]){
[height appendString:string];
}
else if ([currentElement isEqualToString:#"temp"]){
[temp1 appendString:string];
}
else if ([currentElement isEqualToString:#"temp"]){
[temp2 appendString:string];
}
else if ([currentElement isEqualToString:#"people"]){
[people1 appendString:string];
}
else if ([currentElement isEqualToString:#"people"]){
[people2 appendString:string];
}
}
- (void) parserDidEndDocument:(NSXMLParser *)parser {
NSLog(#"feed:%#",feed);
}
the result of nslog is:
feed:(
{
city = city;
people = 4004590;
},
{
width = 340;
height = 120;
},
{
temp = sunny;
people = "";
},
{ ///???? here there is an empty space
},
{
temp = cloudy;
people = "";
},
{
}
)
Now I don't understand why there is a space between first dictionary of desc 1 and desc2, and I don't know how "people" take the result of people1 and people2 in a single string
Can you help me?
I guess your problem is in duplicated chunks of code such as:
else if ([currentElement isEqualToString:#"temp"]){
[temp1 appendString:string];
}
else if ([currentElement isEqualToString:#"temp"]){
[temp2 appendString:string];
}
In this case your first part of code will executed twice and second never.
Check also another parts of your code, yo have several blocks with this issue.
You need to keep track of whether you are parsing the first occurrence of description within the data tag, or the second. This can easily be done with a boolean (if there are only two), or an integer (for multiple) that indicates which of the tags you are currently processing. Then, in the parser:didEndElement: method, you can assign the accumulated data to the correct dictionary based on the flag/counter.
The other possibility, which I use in my XML parsing, is to accumulate characters for one tag at a time, then when I encounter the closing element for that tag, store the characters into the containing element's Dictionary right then. In other words, when I encounter the endTag for temp, I will immediately assign it to the current description tag's dictionary. Then, when I encounter the ending tag for the description tag itself, I can close out that dictionary, set the flag/increment the counter, and continue on with the next tag that is to be parsed.
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
// ... SNIP ...
if ( [ elementName isEqualToString:#"description" ] )
{
curDescription = [ [ NSMutableDictionary alloc ] init ] ;
}
// ... SNIP ...
accumulatedCharacters = [ [ NSMutableString alloc ] init ]
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
// ... SNIP ...
if ( [ elementName isEqualToString:#"temp" ] )
{
[ curDescription setValue:accumulatedCharacters forKey:#"temp" ] ;
}
if ( [ elementName isEqualToString:#"description" ] )
{
// Save the curDescription object, then clear it for reuse on the next
// occurrence of the tag
[ curDescription release ] ;
curDescription = nil ;
}
// ... SNIP ...
[ accumulatedCharacters release ] ;
accumulatedCharacters = nil ;
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
{
[ accumulatedCharacters appendString:string ] ;
}

Resources