Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ulquiorra

macrumors member
Original poster
Jun 17, 2009
38
0
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.
Code:
- (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

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

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

Code:
<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 ?
 
If menuitem is always a child node of workout_mob / menu_mob (not sure which since your code snippet uses workout_mob but your XML snippet uses menu_mob), then here is your problem:
Code:
if([elementName isEqualToString:@"menuitem"]) {
    [B]appDelegate.theChildren = [NSMutableArray new];[/B]
Every time you encounter a new child node (menuitem) you are resetting the array for the parent node (workout_mob).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.