Reputation: 7906
i want to parse the XML file. i am enable to parse simple XML file. but there are little complex XML file
<?xml version="1.0" encoding="utf-8"?>
<Level>
<p id='327'>
<Item>
<Id>5877</Id>
<Type>0</Type>
<Icon>---</Icon>
<Title>Btn1Item1</Title>
</Item>
<Item>
<Id>5925</Id>
<Type>0</Type>
<Icon>---</Icon>
<Title>Btn1Item4</Title>
</Item>
</p>
</Level>
Here i want to get the value of <p>
tag (i mean i want to get the value of attribute id which is 327)
Please suggest
Upvotes: 1
Views: 3985
Reputation: 696
You can use below code to find your "id" value in XML parsing method,
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
if([elementName isEqualToString:@"p"])
{
int idValue = [[attributeDict objectForKey:@"id"] intValue];
NSLog(@"Reading id value :%d", idValue);
}
}
Upvotes: 2
Reputation: 537
In your (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
method, the attributeDict
argument contains all the attributes. For example, to access the 'id' attribute, simply call [attributeDict objectForKey:@"id"]
.
Upvotes: 0