开发者

NSXMLParser and duplicate tags

开发者 https://www.devze.com 2023-01-13 14:03 出处:网络
I have a xml file. That I want to parse with NXXMLParser. I have a开发者_JAVA技巧 basic understanding of how to use NSXMLParser but ive reached this problem were the xml file is using duplicate tags f

I have a xml file. That I want to parse with NXXMLParser. I have a开发者_JAVA技巧 basic understanding of how to use NSXMLParser but ive reached this problem were the xml file is using duplicate tags for different reasons.

The xml file looks a little like this.

<member>
     <name>billy</name>
     <id>1</id>
</member>
<token>
     <name>login token</name>
     <id>1</id>
</token>

<member>
     <name>bob</name>
     <id>2</id>
</member>
<token>
     <name>login token</name>
     <id>2</id>
</token>

Now lets say I created created 4 arrays.

memberName

memberID

tokenName

tokenID

How can I extract the data and assign it to their respective array.


Just have a state variable as a member of the delegate - when you see a "member" tag start set the state to "member", when you see a "token" tag, set the state to "token".

Then when you see the "name" and "id" tag, check the state and add it to the right array.

0

精彩评论

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

关注公众号