0
votes

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

3

3 Answers

1
votes

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.

0
votes

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

how to parse xml using libxml2 in iphone

Cheers

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