1

我无法访问 XML 的节点:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <array>
      <dict>
        <key>cnt_id</key>
        <string>lovenyc</string>
        <key>user</key>
        <string></string>
        <key>emps_cnpj</key>
        <string>11379404000154</string>
        <key>depto_id</key>
        <string>0</string>
        <key>id_device</key>
        <string>7543AF5F-495D-4739-BB83-56BF08CE7DF0</string>
        <key>data_acesso</key>
        <string>2013-01-04 12:48:21</string>
        <key>id_usuario</key>
        <string></string>
        <key>user_fav</key>
        <string>0</string>
        <key>user_like</key>
        <string>0</string>
        <key>user_lat</key>
        <string></string>
      </dict>
    </array>
 </plist>

目标c代码:

-(void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)
namespaceURI qualifiedName:(NSString *) qName attributes:(NSDictionary *)attributeDict
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc]init];
    _xmlObjects = [[NSMutableArray alloc]init];

    NSLog(@"Attribute %@",[attributeDict allKeys]);
    NSLog(@"Attribute Values %@",[attributeDict allValues]);
}

日志总是给我空值,例如,我无法访问该<string>值,有什么建议吗?谢谢

4

1 回答 1

2

使用 Foundation 对象解析属性列表是一项微不足道的单行任务:

NSArray *array = [NSArray arrayWithContentsOfFile:@"PropList.plist"];

文档中的更多信息。

(请注意,您必须使用正确的类 - 如果属性列表的根对象是<dict>,那么您应该使用+ [NSDictionary dictionaryWithContentsOfFile:]。)

于 2013-01-04T18:17:57.650 回答