开发者

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


// 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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜