使用Xcode从xml中提取文本

时间:2012-04-02 01:24:23

标签: objective-c xml xcode extract

我正在努力从xml中创建的表中提取信息,这里是mi文件testXML.xml的一个例子,它在app中:

<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>

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

1 个答案:

答案 0 :(得分:0)

好的...所以我建议改用NSDictionary

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

从dict获取数据:

[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 ..自动搜索,快速

我不明白为什么在这种情况下你会在字典上使用xml