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.
- Is it possible? 开发者_运维问答
- How can i accomplish this.
- Is it secure.
Thanks in advance
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.
精彩评论