androider
androider

Reputation: 449

Event occuring twice in NSXMLParser

I am using NSXMLParser , i have used following code is store in the objects

   - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {

string = [string stringByTrimmingCharactersInSet:
          [NSCharacterSet whitespaceAndNewlineCharacterSet]];

NSLog(element);
NSLog(string);


if(([string length]>0 )||([string isEqualToString:@"c_id"])){

//  NSLog([NSString stringWithFormat:@"%@   %@",element,string]);

    if([element isEqualToString:@"c_id"]){
        if([string isEqualToString:@""]||string==NULL);
        else
            oneCharade.team_id=string;

    }
    else 
        if([element isEqualToString:@"title"]){
            if([string isEqualToString:@""]||string==NULL);
            else
                oneCharade.title=string;


        }

        else 
            if([element isEqualToString:@"desc"]){
                oneCharade.desc=string;
            //  NSLog(string);
                //NSLog(oneCharade.desc);

                [allCharades addObject:oneCharade];


                //[app.itemData addObject:data];
                //  NSLog(@"Object is added %@",searchedData.pid);

            }





}// end of the outer if 


   }




                      - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {

element=elementName;
if([element isEqualToString:@"c_id"]){
    oneCharade=[[XMLTeamData alloc]init];

    //NSLog(@"Object is created");
}


   }// end of the did start Element

           -(void)parserDidEndDocument:(NSXMLParser *)parser{
CharadesAppDelegate *del=(CharadesAppDelegate *)[[UIApplication   sharedApplication]delegate];
[del setServerCharades:allCharades];


//NSLog(@" count :%i",[allCharades count]);

}

but for the desc event occurs for two times as you can see follwing

    2011-11-29 11:49:31.251 Charades[741:207] c_id
    2011-11-29 11:49:31.251 Charades[741:207] 191
    2011-11-29 11:49:31.251 Charades[741:207] title
    2011-11-29 11:49:31.251 Charades[741:207] Todd Philips
    2011-11-29 11:49:31.251 Charades[741:207] desc
    2011-11-29 11:49:31.251 Charades[741:207] Baksm
    2011-11-29 11:49:31.251 Charades[741:207] desc
    2011-11-29 11:49:31.251 Charades[741:207] ällan

you can see here

    <c_id>191</c_id><title>Todd Philips</title><desc>Baksmällan</desc><category>Filmer</category>

but event for description is occuring device, how can resolve this

Upvotes: 0

Views: 173

Answers (1)

Himanshu A Jadav
Himanshu A Jadav

Reputation: 2306

There seems issue with your special character ä data. You can try <desc><![CDATA[Baksmällan]]></desc>

All text in an XML document will be parsed by the parser. But text inside a CDATA section will be ignored by the parser. you can find more here.

Hope this helps.

Upvotes: 1

Related Questions