2012-04-02 48 views
0

我装盘提取从XML做了一桌的信息,这里是心肌梗塞的一个例子文件testXML.xml,它是在应用程序中:提取XML文本和Xcode

<response> 
<responseCode>0</responseCode> 

<rows> 
    <row> 
     <user>1969-01-01</user> 
     <score>1.5434126596E-2</score> 
    </row> 
    <row> 
     <user>1969-02-01</user> 
     <score>1.5489521629000001E-2</score> 
    </row> 
    <row> 
     <user>1969-03-01</user> 
     <score>1.5504809914E-2</score> 
    </row> < /rows> </response> 

我” m试图做的是,在文本字段中写入用户,在xml中搜索并显示标签中同一行的分数。帮助请:S

+0

你自己编写的XML应用程序使用XML在一本字典? – skytz 2012-04-02 01:28:33

+0

是的,这是一个非常简单的XML。 – Rafaalvfe 2012-04-02 01:32:42

回答

0

确定...所以我建议使用的NSDictionary,而不是

NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; 
[dict setObject:@"score1" forKey:@"user1"]; //to set data in the dictionary 
..... 

摆脱字典数据:

[dict objectForKey:@"user1"]; 

保存到文件:

[dict writeToFile:[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"dictionary"] atomically:YES]; 

从文件中读取:

NSMutableDictionary *dict =[NSMutableDictionary dictionaryWithContentsOfFile:[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"dictionary"]]; 

其easyer..it自动搜索,其快速

我不明白你为什么会在这种情况下

+0

在我的xml中有超过500个用户和分数,这不是一个问题吗? – Rafaalvfe 2012-04-02 01:54:38

+0

根本不..字典是设计工作与数以千计的entrys +它的速度优化...所以多数民众赞成 – skytz 2012-04-02 01:56:28

+0

对不起,我是一个新手,我应该在哪里写这个代码? – Rafaalvfe 2012-04-02 02:02:57