Mann
Mann

Reputation: 5507

iPhone connecting XML with NSDictionary's key

I have table with data taken from NSDictionary. For example Each row of table contains Currency Name and rate which are linked using NSDictionary. Now i want to take rate value from XML file over the network. I have made XML file and web server.

  1. Is it possible?
  2. How can i accomplish this.
  3. Is it secure.

Thanks in advance

Upvotes: 0

Views: 129

Answers (1)

Praveen S
Praveen S

Reputation: 10393

After you parse your xml file, use the reference to your dictionary and do the following:

Assuming the xml will have <Currency> conversionrate </currency> format. In your didendelement you can change the value of dictionary items as below:

    - (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{   
        [dictionary setValue:parseditem forKey:elementName];
}

parsedItem can be got from the method :

- (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string

Here you have to take care that the element name has to be unique. You can also use attributes to do the same and add a if condition before adding it to the dictionary.

Upvotes: 1

Related Questions