当前位置: 动力学知识库 > 问答 > 编程问答 >

iphone - Objective-c Read online xml and store values in an Array data structure

问题描述:

I have to read this link's xml

http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml

and parse it to stock in an array with association currency/rate

example:

USD = 1.2948

I know I sould use NSParser but I don't know how create a loop to set array's fields.

Thank you everybody

网友答案:

If you mean NSXMLParser, that is a SAX-style parser, which means you travel the XML tree unidirectionally from beginning to end of file. Every time the parser encounters something significant, it calls one of its delegate methods. In these methods, you read the values and fill your array by adding values one at a time.

It appears awkward at first and the code can become pretty verbose, with lots of conditionals. But SAX parsing is fast and has a small memory footprint.

I strongly recommend studying the examples in Apple's documentation on Event-Driven XML Programming, starting here.

网友答案:

This link will be useful.It is very simple and easy to implement quickly

how to parse xml using libxml2 in iphone

Cheers

网友答案:

I found this tutorial helpful for this: http://www.theappcodeblog.com/2011/05/09/parsing-xml-in-an-iphone-app-tutorial/

网友答案:
// result array is get after use NSXMLPARSER
for (int i=6;i<[resultArray count];i++)
{
   [currencyDict setvalue:[[resultArray Objectatindex:i] valueforkey:@"rate"]
                   forkey:[[resultArray Objectatindex:i] valueforkey:@"currency"]];
}

use this method and the you get currencydict in this format USD = 1.2948 , THB = 39.504 etc

if not understand then post comment to ask question

分享给朋友:
您可能感兴趣的文章:
随机阅读: