0

I'm totally new to XML parse, have an XML structure like..

   <Chapter name = "chap1">
   <pages>one.html</pages>
   <pages>two.html</pages>
   </Chapter>
   Chapter name = "chap2">
   <pages>one.html</pages>
   <pages>two.html</pages>
   </Chapter>
   <Chapter name = "chap3">
   </Chapter>

I want to take each chapters pages separately... i.e if chapter has pages node i want to say YES else NO. How can i parse..I'm using NSXml Parser

Harish
  • 2,496
  • 4
  • 24
  • 48
  • possible duplicate of [NSXMLParser example](http://stackoverflow.com/questions/4705588/nsxmlparser-example) – Vishal Apr 10 '13 at 02:44

2 Answers2

0

You have to try like this,

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
     if ([elementName isEqualToString:@"Chapter"]) 
     {
         ChapterOneFlag = YES;//use this as BOOL
     }
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSMutableString *)string
{
        buffContent=[buffContent stringByAppendingString:string];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
      if (ChapterOneFlag == YES)
      {
        if ([elementName isEqualToString:@"pages"]) 
        { 
            [yourArr addObject:buffContent];
        }
     }
}

is this the code you want?. Here you can use youArr. It will come separately.

sathiamoorthy
  • 1,488
  • 1
  • 13
  • 23
-2

You have to use NSXMLParser for that

look at the programming guide here : NSXMLParser Programming Guide

Burhanuddin Sunelwala
  • 5,318
  • 3
  • 25
  • 51