0

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

Michele
  • 1
  • 1

3 Answers3

1

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.

mvexel
  • 1,093
  • 1
  • 10
  • 25
  • Ok so the loop is something line i=0 foreach (element in tree){ do this i++ } – Michele Jan 12 '11 at 09:51
  • No, like I said, there is no looping when you use NSXMLParser. You might benefit from reading up on XML programming in iOS starting with the link I provided. – mvexel Jan 12 '11 at 10:48
0
// 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

Josh Lee
  • 171,072
  • 38
  • 269
  • 275
GhostRider
  • 1,197
  • 10
  • 19
  • Ok that's good. Only onthe thing. I only found code to read local xml files. How did I say to iphone to look for the xml online? – Michele Jan 12 '11 at 09:55
0

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

how to parse xml using libxml2 in iphone

Cheers

Community
  • 1
  • 1
Aditya
  • 4,414
  • 5
  • 29
  • 40