0

I am new to iPhone,

I want to fetch all the value of <text> tag from my local .html page and i want to store it in my array.

For eg: toc.html is my html file, from this file i want to fetch all the value of <text> tag.

Here is my html file,

<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>

finally my array should contain:

array at 0: Cover
array at 1: News
array at 2: Report
array at 3: Economy Update

Any help will be appriciated.

dhaval
  • 129
  • 1
  • 8

1 Answers1

1

Try,

- (NSString *)dataFilePath:(BOOL)forSave {
        //TOC is a path of your `html` file
        return TOC;
    }

stores contents of <text> insides array

-(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]];
        }
    }

}
Krunal
  • 6,440
  • 21
  • 91
  • 155