I have searched for my prob and found the various solution on web like :
Using the British pound sign in an XML feed to be read by an iPhone
Special Characters in NSString from HTML
but it is not fruitful for me as after reading xml I am saving it in my DB.
Here is the xml :
<root>
−<Discounts>
<DiscountID>1</DiscountID>
<Title>WeekEnd Offers</Title>
<Description>Offer upto 50%</Description>
<SalePrice>50</SalePrice>
<RegularPrice>100</RegularPrice>
<CreatedDate>11/14/2011</CreatedDate>
<LastModifiedDate>11/14/2011</LastModifiedDate>
<Status>1</Status>
<PhotoPath>/photos/documents/coupzila/hiteshi-logo.png</PhotoPath>
</Discounts>
</root>
m getting the description in string as :
NSString * strDescription = [item.mdictXMLTagsData valueForKey:@"Description"];
NSLog(@"String in description is : ",strDescription);
but the description field is getting null in console and i cant store it in my DB.
pls suggest how can I read and store special characters to my DB.
One more thing i came to know that % is the keyword to read % sign but i dont know how n where to apply this.
pls help!!!
EDIT : my current code.
-(void)CallAPIForDetails
{
//RequestType = 2;
//UIApplication sharedApplication].networkActivityIndicatorVisible=YES;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
ParsingAPI *api = [[ParsingAPI alloc]init];
api.delegate = self;
NSString *strurl = [@"" stringByAppendingFormat: @"http://192.168.1.108/Coupzila/api/default.aspx?method=GetData&RequestType=Discounts&StoreID=%d",StoreId];
NSLog(@"URL : %@",strurl);
strurl = [strurl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
api.strEntityName=@"Discounts";
api.arrayXMLTags = nil;
api.arrayXMLAttributeTags = nil;
[api parseXMLFileAtURL:[NSURL URLWithString:strurl] showProgress:NO];
[api release];
[pool release];
}
- (void)feedDataArray:(ParsingAPI *)feed didFindItemsArray:(NSMutableArray *)items
{
/*
if(RequestType == 2 )
{*/
NSMutableArray *arraydeleteDetails = [CoreDataAPIMethods getObjectsFromContext:@"DiscountsDetail" :@"DiscountId" :YES :self.managedObjectContext];
for (float i=0;i<[arraydeleteDetails count];i++)
{
[self.managedObjectContext deleteObject:[arraydeleteDetails objectAtIndex:i]];
NSError *error;
if (![self.managedObjectContext save:&error]) {
// Handle the error...
}
}
for (float i=0;i<[items count];i++)
{
ParsingItem *item = [items objectAtIndex:i];
NSMutableArray *arr = [CoreDataAPIMethods getObjectsFromContext:@"DiscountsDetail" :@"Index" :NO :self.managedObjectContext];
if ([arr count] > 0)
{
DiscountsDetail * DiscountsDetailObject = [arr objectAtIndex:0];
NewEntryID = [DiscountsDetailObject.Index intValue] +1;
}
else
{
NewEntryID = 1;
}
/*
if (countImage == 0)
{
countImage = NewEntryID;
}*/
//Now add the data in database
DiscountsDetail *data = (DiscountsDetail*)[NSEntityDescription insertNewObjectForEntityForName:@"DiscountsDetail" inManagedObjectContext:self.managedObjectContext];
data.DiscountId = [NSNumber numberWithInt:[[item.mdictXMLTagsData valueForKey:@"DiscountID"] intValue ]];
data.Title = [item.mdictXMLTagsData valueForKey:@"Title"];
data.SalePrize = [item.mdictXMLTagsData valueForKey:@"SalePrice"];
data.RegularPrize = [item.mdictXMLTagsData valueForKey:@"RegularPrice"];
//data.Description = @"This is test descriptionsakdj bfaisdfj bgasdlkab gfdil ufghiub nrungdfg bndfiosggn iouer5nn gdfnsngdfsu gndklfngdufn gkdfjlbgn lidsfub gdilufbf gldfb ghdfsiosa ifgho aibfg iodfb dfug hbdfg iygofadqi igdfhaibg adofibg ifdbgioadfbg adfigyb asg ig agiobfg finish" ;
NSString * strDescription = [item.mdictXMLTagsData valueForKey:@"Description"];
NSXMLParser * parser = [item.mdictXMLTagsData valueForKey:@"Description"];
[self parser:parser foundCharacters:strDescription];
NSLog(@"String in description is : ",strDescription);
data.Description =[item.mdictXMLTagsData valueForKey:@"Description"];
data.Index = [NSNumber numberWithInt:NewEntryID];
NSLog(@"Description is :",data.Description);
if ([item.mdictXMLTagsData valueForKey:@"PhotoPath"] != nil)
{
NSString *photopath=@"http://192.168.1.108/Coupzila/";
NSData *dataimage=[NSData dataWithContentsOfURL:[NSURL URLWithString:[photopath stringByAppendingString:[item.mdictXMLTagsData valueForKey:@"PhotoPath"]]]];
data.ImageDiscounts = dataimage;
}
NSError *error;
if (![self.managedObjectContext save:&error])
{
// Handle the error...
}
self.arrayDiscountDetails = [CoreDataAPIMethods getObjectsFromContext:@"DiscountsDetail" :@"DiscountId" :NO :self.managedObjectContext];
}
}