I am working on an iPhone application where I am getting data from server using php webservice and need to show records in table view. All was going well, but today i compiled code and run in simulator and found data is not parsing by parser while it is received from server as xml. I check the tag name in xml and parsing delegate methods.
here is the xml data and tag name.
<?xml version="1.0" encoding="UTF-8"?
ROOT>
ROW>
PostID>6BF718DD-E91B-4F8E-8EDB-520D66E02D60 /PostID>
PostDate>Dec 1 2010 10:31PM /PostDate>
Post>resume on mywebsite /Post>
FirstName>Testing /FirstName>
LastName>Team /LastName>
ProfileImage>http://mywebsite.com/upload_pic/thumbnail_%7B94808EC1-06DF-4AC2-B1C3-21DC5108695C%7D.jpg /ProfileImage>
Community>the park/Community>
NoOfComments>0 /NoOfComments>
/ROW
/ROOT
static NSString *kXMLtagName_ROOT = @"ROOT";
static NSString *kXMLtagName_Row = @"ROW";
static NSString *kXMLtagName_PostID = @"PostID";
static NSString *kXMLtagName_PostDate = @"PostDate";
static NSString *kXMLtagName_Post = @"Post";
static NSString *kXMLtagName_FirstName = @"FirstName";
static NSString *kXMLtagName_LastName = @"LastName";
static NSString *kXMLtagName_ProfileImage = @"ProfileImage";
static NSString *kXMLtagName_Community = @"Community";
static NSString *kXMLtagName_NoOfComments = @"NoOfComments";
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if ([currentElement isEqualToString:kXMLtagName_PostID])
{
NSLog(@"postid = %@",string);
if(string)
//[dictCommunityInfo setObject:string forKey:@"PostID"];
[arrMainPostInfo addObject:string];
}
else if ([currentElement isEqualToString:kXMLtagName_PostDate])
{
NSLog(@"PostDate = %@",string);
if(string)
[arrMainPostInfo addObject:string];
}
else if ([currentElement isEqualToString:kXMLtagName_Post])
{
NSLog(@"Posted data = %@",string);
//if(string)
[arrMainPostInfo addObject:string];
}
else if ([currentElement isEqualToString:kXMLtagName_FirstName])
{
NSLog(@"fName=%@ ",string);
if(string)
[arrMainPostInfo addObject:string];
}
else if ([currentElement isEqualToString:kXMLtagName_LastName])
{
NSLog(@"lName=%@ ",string);
if(string)
[arrMainPostInfo addObject:string];
}
else if ([currentElement isEqualToString:kXMLtagName_ProfileImage])
{
NSLog(@"ProfileImageUrl=%@ ",string);
if(string)
[arrMainPostInfo addObject:string];
}
else if ([currentElement isEqualToString:kXMLtagName_Community])
{
NSLog(@"Community=%@ ",string);
if(string)
[arrMainPostInfo addObject:string];
}
else if ([currentElement isEqualToString:kXMLtagName_CommentID])
{
NSLog(@"CommentID = %@",string);
if(string)
[dictComentsInfo setObject:string forKey:@"CommentID"];
}
else if ([currentElement isEqualToString:kXMLtagName_CommentPostDate])
{
NSLog(@"CommentPostDate = %@",string);
if(string)
[dictComentsInfo setObject:string forKey:@"CommentPostDate"];
}
else if ([currentElement isEqualToString:kXMLtagName_CommentPost])
{
NSLog(@"CommentPost data = %@",string);
if(string)
[dictComentsInfo setObject:string forKey:@"CommentPost"];
}
else if ([currentElement isEqualToString:kXMLtagName_CommentFirstName])
{
NSLog(@"CommentFirstName=%@ ",string);
if(string)
[dictComentsInfo setObject:string forKey:@"CommentFirstName"];
}
else if ([currentElement isEqualToString:kXMLtagName_CommentLastName])
{
NSLog(@"CommentLastName=%@ ",string);
if(string)
[dictComentsInfo setObject:string forKey:@"CommentLastName"];
}
else if ([currentElement isEqualToString:kXMLtagName_ComentProfileImage])
{
NSLog(@"CommentProfileImage=%@ ",string);
if(string)
[dictComentsInfo setObject:string forKey:@"CommentProfileImage"];
}
else if ([currentElement isEqualToString:kXMLtagName_UserCommunity])
{
NSLog(@"CommentCommunity=%@ ",string);
if(string)
[dictComentsInfo setObject:string forKey:@"CommentCommunity"];
}
}
parser is checking only following three tag and leave other all tags
if ([currentElement isEqualToString:kXMLtagName_PostID])
{
NSLog(@"postid = %@",string);
if(string)
//[dictCommunityInfo setObject:string forKey:@"PostID"];
[arrMainPostInfo addObject:string];
}
else if ([currentElement isEqualToString:kXMLtagName_PostDate])
{
NSLog(@"PostDate = %@",string);
if(string)
[arrMainPostInfo addObject:string];
}
else if ([currentElement isEqualToString:kXMLtagName_Post])
{
NSLog(@"Posted data = %@",string);
//if(string)
[arrMainPostInfo addObject:string];
开发者_JS百科
}
Any Idea about this, I am using xcode 3.2.1 even I check on device 3gs same in that. I am socked that all the code was going fine before today I re check the web-service and xml tag name.
I got solution. Actually a special character was found in () thats why xml parser was unable to parse that, ignores the other tag.
I change that character and everything get working.
Thanks
精彩评论