gpt4 book ai didi

objective-c - 使用 XMLParser 访问正确的 XML 节点

转载 作者:行者123 更新时间:2023-11-29 11:04:50 24 4
gpt4 key购买 nike

我无法访问 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>

objective-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>值(value)例如,有什么建议吗?谢谢

最佳答案

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

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

更多信息在 documentation .

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

关于objective-c - 使用 XMLParser 访问正确的 XML 节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14162325/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com