我是iPhone的新手,
我想从本地<text>页面中获取.html标记的所有值,并将其存储在数组中。
对于示例:toc.html是我的html文件,我想从这个文件中获取<text>标记的所有值。
这是我的html文件
<navMap>
<navPoint class="chapter" id="navpoint-1" playOrder="1">
<navLabel>
<text>Cover</text>
</navLabel>
<content src="Morning Insight 26 April - K S 2/Morning Insight 26 April - K S 2/Morning Insight 26 April - K S/Morning Insight 26 April - K S/Morning Insight/OEBPS/first.html"/>
</navPoint>
<navPoint class="chapter" id="navpoint-2" playOrder="2">
<navLabel>
<text>News</text>
</navLabel>
<content src="Morning Insight 26 April - K S 2/Morning Insight 26 April - K S 2/Morning Insight 26 April - K S/Morning Insight 26 April - K S/Morning Insight/OEBPS/1.html"/>
</navPoint>
<navPoint class="chapter" id="navpoint-3" playOrder="3">
<navLabel>
<text>Report</text>
</navLabel>
<content src="Morning Insight 26 April - K S 2/Morning Insight 26 April - K S 2/Morning Insight 26 April - K S/Morning Insight 26 April - K S/Morning Insight/OEBPS/2.html"/>
</navPoint>
<navPoint class="chapter" id="navpoint-4" playOrder="4">
<navLabel>
<text>Economy Update</text>
</navLabel>
<content src="Morning Insight 26 April - K S 2/Morning Insight 26 April - K S 2/Morning Insight 26 April - K S/Morning Insight 26 April - K S/Morning Insight/OEBPS/3.html"/>
</navPoint>
<navMap>最后,我的数组应该包含:
array at 0: Cover
array at 1: News
array at 2: Report
array at 3: Economy Update任何帮助都将是见习的.
发布于 2012-07-23 12:50:09
试试看
- (NSString *)dataFilePath:(BOOL)forSave {
//TOC is a path of your `html` file
return TOC;
}<text> 存储内部数组的内容。
-(void)viewDidAppear:(BOOL)animated{
[super viewDidLoad];
TOCArray=[[NSMutableArray alloc]init];
NSString *filePath = [self dataFilePath:FALSE];
NSData *response = [[NSMutableData alloc] initWithContentsOfFile:filePath];
GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:response options:0 error:nil];
NSArray *navPoints = [[[doc.rootElement elementsForName:@"navMap"] lastObject] elementsForName:@"navPoint"];
for (GDataXMLElement *m in navPoints)
{
NSArray *navLabel = [m elementsForName:@"navLabel"];
for (GDataXMLElement *e in navLabel)
{
NSArray *text = [e elementsForName:@"text"];
[TOCArray addObject:[text objectAtIndex:0]];
}
}
}https://stackoverflow.com/questions/11594014
复制相似问题