为什么我的字典里的Children没有填满
大家好,我正在使用 NSXMLParser 来解析一些 xml 数据。 我正在使用这些数据构建树表示,以创建钻取表的层次结构。
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
if([elementName isEqualToString:@"exercises"]) {
//init tree
appDelegate.Tree = [NSMutableDictionary new];
appDelegate.Rows = [NSMutableArray new];
[appDelegate.Tree setObject:appDelegate.Rows forKey:@"Rows"];
...
现在,如果我的 xml 中的元素 menuitem 被读取,那么它将初始化并将 theChildren 添加到 menu_item 字典中
if([elementName isEqualToString:@"menuitem"]) {
appDelegate.theChildren = [NSMutableArray new];
[appDelegate.menu_item setObject:appDelegate.theChildren forKey:@"Children"];
这一切都按计划进行。
然而,以下内容并没有按照我想要的方式进行。 当我看到另一个标签(workout_mob)时,我希望填充 theChildren,而这只发生在底部词典项目中。
http://img188.imageshack.us/img188/7052/picture4efx.png
if([elementName isEqualToString:@"workout_mob"]) {
appDelegate.work_out_mob = [NSMutableDictionary new];
[appDelegate.theChildren addObject:appDelegate.work_out_mob];
有谁知道为什么它至少没有填充我的两个项目吗?我的意思是它将 Children 数组添加到它们两个中,所以为什么只为其余的底部一个。如果我在 xml 代码中添加另一个 xmlline,如下所示:
<menu_mob>
<menuitem id="1" text="Press this for exercises" pic="workout" />
<menuitem id="2" text="VirtuaGym online" pic="online" />
*<menuitem id="3" text="the Added Line" pic="online" />*
</menu_mob>
那么它会将所有子项添加到底部菜单项(想象另一个字典项 (3))。 那么为什么呢?
Hello all I'm using NSXMLParser to parse some xml data.
I'm using this data to build a Tree representation to create a hierarchy for a drilldowntable.
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
if([elementName isEqualToString:@"exercises"]) {
//init tree
appDelegate.Tree = [NSMutableDictionary new];
appDelegate.Rows = [NSMutableArray new];
[appDelegate.Tree setObject:appDelegate.Rows forKey:@"Rows"];
...
Now if the element menuitem in my xml is being read then it will initialize and add theChildren to the menu_item dictionary
if([elementName isEqualToString:@"menuitem"]) {
appDelegate.theChildren = [NSMutableArray new];
[appDelegate.menu_item setObject:appDelegate.theChildren forKey:@"Children"];
This is all going according to plan.
However the following is not going the way I want it to go.
When I see another tag (workout_mob) I want theChildren to be filled and this only happens with the bottom dictionary item.
http://img188.imageshack.us/img188/7052/picture4efx.png
if([elementName isEqualToString:@"workout_mob"]) {
appDelegate.work_out_mob = [NSMutableDictionary new];
[appDelegate.theChildren addObject:appDelegate.work_out_mob];
Does anyone have a clue as to why it isn't at least filling both my items I mean it's adding the Children array to the both of them so why just the bottom one for the rest. If I add another xmlline in my xml code like so:
<menu_mob>
<menuitem id="1" text="Press this for exercises" pic="workout" />
<menuitem id="2" text="VirtuaGym online" pic="online" />
*<menuitem id="3" text="the Added Line" pic="online" />*
</menu_mob>
then it will add all the Children items to the bottom menuitem ( imagine another dictionary item (3)).
So why ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,看来我正在重置我的数组;)所以问题解决了。
MMm it seems I was resetting my array ;) so problem solved.