xml parsing
xml parsing
- Subject: xml parsing
- From: developers mac <email@hidden>
- Date: Wed, 1 Apr 2009 18:31:55 +0530
Hi there,
I have to parse a xml & return the values for val & id (attribute). I have pasted a sample xml below.
<response>
<field>
<values>
<val id="AL"> Alabama</val>
.
.
.
<val id="WY">Wyoming</val>
</values>
</field>
<field>
<values>
<val id="1">Australia</val>
.
.
.
<val id="150">Zambia</val>
</values>
</field>
</response>
I am able to retrieve the val(Alabama, Austalia...) & display it in a table view. I need to get the attribute values (AL, 1) - to know which val has been selected. I need to get the attribute value. but i am not sure to get the attribute value according to the click of the val. Can some help me to get through this one please!!!!
Also i am able to get the attribute values in didstartelement of xml parser by :
tagid = [attributeDict objectForKey:@"id"];
But I am not aware of how to add this value to a array something similar to :
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
currentElement = [elementName copy];
if ([elementName isEqualToString:@"val"]) {
item = [[NSMutableDictionary alloc] init];
tagid = [attributeDict objectForKey:@"id"];
( I am getting all the values of attribute here)
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"val"]) {
[item setObject:errorcode forKey:@"val"];
[item setObject:obtID forKey:@"Id"];
[item objectForKey:@"id"];
[stories addObject:[item copy]];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
if ([currentElement isEqualToString:@"val"]){
[errorcode appendString:string];
} else if ([currentElement isEqualToString:@"Id"]) {
obtrowid = string;
[obtID appendString:string];
}
}
I need to retrieve the values of
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
retselval = [[stories objectAtIndex: storyIndex] objectForKey: @"val"];
//retseltag = [dupattr objectForKey:@"id"];
( This is where I am trying to read the attribute values)
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden