我想分析了「比較」裏面的html標籤內容節點解析錨標籤和使用NSXMLParse
<comparison>
<a href="/cgi-bin/amazon.cgi?B0050AMJYU">Amazon.com</a>
($34.36) |
<a href="/cgi-bin/walmart.cgi?16904483">Walmart.com</a>
($34.36) |
<a href="/cgi-bin/rakuten.cgi?219782579">Rakuten.com</a>
($34.36) |
<a href="/cgi-bin/bestbuy1.cgi?mp1307815397">BestBuy.com</a>
($34.36)
</comparison>
我得到的輸出是:
BestBuy.com ($34.36)
預期的輸出:
Amazon.com ($34.36)
Walmart.com ($34.36)
Rakuten.com ($34.36)
BestBuy.com ($34.36)
但我想顯示所有的四個項目。
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;
}
}
什麼是您的解析代碼? – Larme