iPhone how to parse nested xml file and display in tableview
<p>I have the following xml file</p>

<pre><code>&lt;Root&gt;
&lt;propertytype value="Property1"&gt;
&lt;property&gt;
&lt;Property_Name&gt;Name&lt;/Property_Name&gt;
&lt;/defaultValue&gt;
&lt;/property&gt;
&lt;property&gt;
&lt;Property_Name&gt;Address&lt;/Property_Name&gt;
&lt;/defaultValue&gt;
&lt;/property&gt;
&lt;property&gt;
&lt;Property_Name&gt;Age&lt;/Property_Name&gt;
&lt;/defaultValue&gt;
&lt;/property&gt;
&lt;/propertytype&gt;
&lt;propertytype value="Property2"&gt;
&lt;property&gt;
&lt;Property_Name&gt;Cell Number&lt;/Property_Name&gt;
&lt;/defaultValue&gt;
&lt;/property&gt;
&lt;property&gt;
&lt;Property_Name&gt;E-mail&lt;/Property_Name&gt;
&lt;/defaultValue&gt;
&lt;/property&gt;
&lt;/propertytype&gt;
&lt;/Root&gt;
</code></pre>

<p>What i need is propertytype attributes value need to display in tableview and whenever i click on that value say "Property1", the respective elements(Name,Address and Age) need to be displayed in other view</p>

<p>Please help me?</p>

<p>I used the NSXMLParser and code is pasted below</p>

<pre><code>- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 
    attributes:(NSDictionary *)attributeDict {



    if([elementName isEqualToString:@"Root"]) {
        //Initialize the array.
        appDelegate.subtype = [[NSMutableArray alloc] init];
        appDelegate.books = [[NSMutableArray alloc] init];




    }
    else if([elementName isEqualToString:@"propertytype"]) {




        sub=[[Subexptype alloc]init];

        //Extract the attribute here.

        sub.bookID=[attributeDict objectForKey:@"value"];

        NSLog(@"Reading id value :%@", sub.bookID);

        }
    else if([elementName isEqualToString:@"property"]) {

        aBook = [[Book alloc] init];


    }




    NSLog(@"Processing Element: %@", elementName);
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { 

    if(!currentElementValue) 
        currentElementValue = [[NSMutableString alloc] initWithString:string];
    else
        [currentElementValue appendString:string];

    NSLog(@"Processing Value: %@", currentElementValue);

}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {



    if([elementName isEqualToString:@"Root"])
        return;

    //There is nothing to do if we encounter the Books element here.
    //If we encounter the Book element howevere, we want to add the book object to the array
    // and release the object.

    if([elementName isEqualToString:@"propertytype"]){


        [appDelegate.subtype addObject:sub];
        [sub release];
        sub=nil;
    }


    else if([elementName isEqualToString:@"property"]){
        [appDelegate.books addObject:aBook];


        [aBook release];
        aBook = nil;
    }
    else
        [aBook setValue:currentElementValue forKey:elementName];



    [currentElementValue release];
    currentElementValue = nil;
}
</code></pre>

<p>Now, i can able to get attribute value like "Property1" and "Property2" in tableview and whenever i click on Property1 or Property2 i get all elements like Name,Address,Age,E-mail and Cell Number.</p>

<p>But i don't want this way, if i click on Property1 its respective elements like Name, Address and Age shuold be displayed and if i click on property2 its elements Cell Number and E-mail shuold be displayed</p>

<p>Please help me where i am wrong</p>
