i am trying to parse xml in objective c.my xml has following no开发者_如何学Cde
<Item>Male</Item>
<Item>Female</Item>
</RadioButton>
<Item>i-pad</Item>
<Item>i-pod</Item>
</RadioButton>
now i want to generate comma separated string for each radiobutton i.e. first string will be Male,Female and second one is i-pad,i-pod
please help me
Use NSXMLParser
To join the string refer following function in NSArray class
- (NSString *)componentsJoinedByString:(NSString *)separator
to achieve XML parsing in objective-c,use NSXMLParser
class and set a delegate to NSXMLParserDelegate
protocal,in the delegate implement
parser:didStartElement:namespaceURI:qualifiedName:attributes:
parser:didEndElement:namespaceURI:qualifiedName:
and
parser:foundCharacters:
methods. Each time you encounter "RadioButton" element create a mutable string. Each time you encounter end of "Item" element add the characters found so far(through foundCharacters method) to the mutable string created, with a "," at the end. Each time you encounter end of "RadioButton" remove the last character(i.e ,) from mutable string. Save the mutable strings to an array appropriately,you will have the 2 required out put strings in this array.
for comma, use this concept
itemname like NSString
ItemName = [ItemName stringByAppendingFormat:@", "];
精彩评论