开发者

how to parse XML in objective c and generated comma separated string

开发者 https://www.devze.com 2023-03-05 23:51 出处:网络
i am trying to parse xml in objective c.my xml has following no开发者_如何学Cde <Item>Male</Item>

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 NSXMLParserDelegateprotocal,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:@", "];
0

精彩评论

暂无评论...
验证码 换一张
取 消