ios将xml文件序列化到nsmutable字典中,其中xml有多个atribute



我正在尝试序列化这样的xml:

<Rows>
<RowOne SKATERID="706" MANUFACTURER="A-DZG" ISFACT="F" ISSKATE="F">True</RowOne>
<RowTwo SKATERID="318" MANUFACTURER="A-FGW" ISFACT="F" ISSKATE="T">True</RowTwo>
<RowThree SKATERID="458" MANUFACTURER="A-OPJ" ISFACT="F" ISSKATE="T">False</RowThree>
<RowFour SKATERID="178" MANUFACTURER="A-JSL" ISFACT="F" ISSKATE="T">True</RowFour>
</Rows>

但我的问题是,最好的方法是什么,包括心房肌。到目前为止,我已经让我的解析器工作了,当我检测到节点有属性时,我会将这些属性发送到本地nsmutabledictionay。但我的问题是如何映射属性的dictionary和节点的值。例如,在RowOne中,该值为true,但它具有以下属性SKATERID="706"MANUFACTURE="A-DZG"ISFACT="F"ISSKATE="F"。

in-(void)语法分析器:(NSXMLParser*)语法分析器didStartElement:(NSString*)elementName命名空间URI:(NSString*)命名空间URI限定名称:(NSString*qName属性:(NSDictionary*)attributeDict{

我有这样的代码:

if ([attributeDict count] != 0) {
    self.myDict = [[NSDictionary alloc] initWithDictionary:attributeDict];
}
in -(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{

我想弄清楚用节点的值序列化字典的最佳方式是什么

我将非常感谢您的帮助

编辑:重读你的问题后,你所说的"连载"是什么意思?在等待您的回答之前,下面的解决方案可能不是您想要的。

如果您的XML属性是静态的,我建议创建一个自定义类myRowClass,它的操作方式如下。。。

myRow.SkaterID //NSString
myRow.Manufacturer //NSString
myRow.IsFact //BOOL
myRow.IsSkate //BOOL

有了这个自定义类,您可以像这样将每个myRow对象推送到您的NSMutableDictionary中。。。

[myDict setObject:myRow forKey:@"RowOne"]
myRow = nil;
myRowClass *myRow = [[myRowClass alloc]init];
<...Iterate through next XML Node...>
[myDict setObject:myRow forKey:@"RowTwo"]

然后,当你需要访问你的数据时,你可以这样检索。。。

NSString *myCurrentSkaterID = [[myDict objectForKey:@"RowTwo"].SkaterID]

myRowClass *myCurrentRow = [[myRowClass alloc]init];
myCurrentRow = [myDict objectForKey:@"RowTwo"];
NSString *myCurrentSkaterID = myCurrentRow.SkaterID;

这就是我想要的http://troybrant.net/blog/2010/09/simple-xml-to-nsdictionary-converter/

最新更新