开发者

iPhone connecting XML with NSDictionary's key

开发者 https://www.devze.com 2023-03-25 01:52 出处:网络
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

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. 开发者_运维问答
  3. How can i accomplish this.
  4. 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.

0

精彩评论

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