Reputation: 10984
HI, all, i am not sure how to write if and else condition in order to parse xml. this is how my returned xml looks like this.
<?xml version="1.0"?>
<a><a1>A</a1></a>
<b><b1>B</b1></b>
<c><c1>C</c1></c>
<d><d1>D</d1></d>
<e><e1>E</e1></e>
<f><f1>F</f1></f>
<g><g1>G</g1></g>
i tried various condition, but i am not able to properly navigate through each node.
How should i write if / else condition in
"-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName
attributes: (NSDictionary *)attributeDict
{
//if and else condition here
if([elementName isEqualToString:@"a"]) {
}
else if([elementName isEqualToString:@"b"]) {
}
…………
}"
and "-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {}"
and finally in here
"-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
//if else condition here
if([elementName isEqualToString:@"a"]) {
}
else if([elementName isEqualToString:@"b"]) {
}
……
}
"
i need to pass the returned values from xml like, A,B,C to NSSTring for further programming..but i am not even able to parse it.
thanks Suggestions are always appreciated
Upvotes: 0
Views: 97
Reputation: 31782
As always, the documentation on NSXMLParser
is excellent. What you probably want to do is implement the delegate method parser:foundCharacters:
and accumulate the text inside your nodes (i.e., with an NSMutableString
). didStartElement:
and didEndElement:
will tell you when you enter and exit elements, as you already know. From there it's just a matter of storing the text in a suitable data structure for further processing.
Upvotes: 1