[英]HTML Parsing in iphone sdk
I am using hpple from git for parsing HTML.我正在使用来自 git 的 hpple 来解析 HTML。 It working fine.它工作正常。 But when I get the parsed NSString I found that in this string double inverted comma (")and single (') are replaced by some other symbol like,Äô. How can I get the correct string? I have tried to replace these characters but its not working.但是当我得到解析的 NSString 时,我发现在这个字符串中,双引号 (") 和单引号 (') 被替换为其他符号,例如,Äô。我怎样才能得到正确的字符串?我试图替换这些字符但是它不工作。
Check out this link it solved my problem看看这个链接它解决了我的问题
https://github.com/mwaterfall/MWFeedParser
Here the steps to add the code这里是添加代码的步骤
Add all the classes,except detailtableviewcontroller and Rootviewcontroller from the code you downloaded from the link. Then add #import "MWFeedParser.h" in your.h file where you are parsing .Then add // Parsing
MWFeedParser *feedParser;
NSMutableArray *parsedItems;
// Displaying
NSArray *itemsToDisplay;
NSDateFormatter *formatter;and /***mwfeed (*/
@property (nonatomic, retain) NSArray *itemsToDisplay;
/*------------*/
Then in .m add the codeformatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterShortStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
parsedItems = [[NSMutableArray alloc] init];
self.itemsToDisplay = [NSArray array];
// Parse
NSURL *feedURL = [NSURL URLWithString:@"http://feeds.feedburner.com/yummydietfood?format=xml"];
feedParser = [[MWFeedParser alloc] initWithFeedURL:feedURL];
feedParser.delegate = self;
feedParser.feedParseType = ParseTypeFull; // Parse feed info and all items
feedParser.connectionType = ConnectionTypeAsynchronously;
[feedParser parse];
#pragma mark -
#pragma mark MWFeedParserDelegate
- (void)feedParserDidStart:(MWFeedParser *)parser {
//[UIApplication sharedApplication].networkActivityIndicatorVisible=YES;
NSLog(@"Started Parsing: %@", parser.url);
}
- (void)feedParser:(MWFeedParser *)parser didParseFeedInfo:(MWFeedInfo *)info {
NSLog(@"Parsed Feed Info: “%@”", info.title);
//self.title = info.title;
}
- (void)feedParser:(MWFeedParser *)parser didParseFeedItem:(MWFeedItem *)item {
NSLog(@"Parsed Feed Item: “%@”", item.title);
if (item) [parsedItems addObject:item];
}
- (void)feedParserDidFinish:(MWFeedParser *)parser {
NSLog(@"Finished Parsing%@", (parser.stopped ? @" (Stopped)" : @""));
self.itemsToDisplay = [parsedItems sortedArrayUsingDescriptors:
[NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:@"date"
ascending:NO] autorelease]]];
[UIApplication sharedApplication].networkActivityIndicatorVisible=YES;
//[self performSelector:@selector(loadData)];
[self performSelector:@selector(loadDataWithOperation)];
}
- (void)feedParser:(MWFeedParser *)parser didFailWithError:(NSError *)error {
NSLog(@"Finished Parsing With Error: %@", error);
UIAlertView *erroralert = [[UIAlertView alloc]initWithTitle:@"Error!" message:@"Problem connecting server, try again in few minutes" delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[erroralert show];
[erroralert release];
self.itemsToDisplay = [NSArray array];
[parsedItems removeAllObjects];
self.tbl.userInteractionEnabled = YES;
[self.tbl reloadData];
}
and where you need the data parsed by the parser called this line code并且您需要由解析器解析的数据称为此行代码
if (item) {
NSString *itemTitle = item.title ? [item.title stringByConvertingHTMLToPlainText] : @"[No Title]";
lbl.text = itemTitle;
}
else {
lbl.text=@"No Title";
}
Check your encoding;检查您的编码; bottom-line is you're probably getting the HTML in UTF-8 and the string in ISO-8859-1.底线是您可能在 UTF-8 中获得 HTML 和 ISO-8859-1 中的字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.