Following on the same path as suggested to take a step back and examine what you want to happen, launch Property List Editor, create a Property List file, and manually add the items from your XML scenarios to determine what you really want to happen for each item you encounter.
On 12/28/2010 10:34 AM, "Sandro Noël" <apple.li...@gestosoft.com> wrote: >Greg, thank you. > >the glitch that breaks all my current logic is when there are elements >with the same name at the same level. >for instance in a RSS, > >rss > chanel > item > item > item > > >this breaks the logic I can apply to a NSDictionary, because the previous >item gets overwritten with the current one. >That is why I've attempted to put them in array's but that had adverse >effects also. > >This procedure produces the correct results if there is no repeating >elements at the same level, >- (NSDictionary *) plist{ > NSMutableDictionary *resultDict = [[[NSMutableDictionary alloc] init] >autorelease]; > if ([self hasChildren]){ > NSMutableDictionary *child = [[[NSMutableDictionary alloc]init] >autorelease]; > for (OSXMLElement *element in _children){ > [child addEntriesFromDictionary:[element plist]]; > } > [resultDict setValue:child forKey:_elementName]; > } > else { > [resultDict setValue:_elementText forKey:_elementName]; > } > return resultDict; >} > > >I've asked the list because I seem to be in an impasse here with this >particular logic problem. >I'm sure i'm not the only one who had that unfortunate mind block. :) > >best regards. >Sandro. > > >On 2010-12-28, at 1:10 PM, Greg Guerin wrote: > >> Sandro Noël wrote: >> >>> - (NSDictionary *) plist{ >>> NSMutableDictionary *resultDict = [[[NSMutableDictionary alloc] >>>init] autorelease]; >>> if ([self hasChildren]){ >>> NSMutableArray *child = [[[NSMutableArray alloc]init] >>>autorelease]; >>> for (OSXMLElement *element in _children){ >>> // if thiselement has children add them to an array >>> [child addObject:[element plist]]; >>> } >>> [resultDict setValue:child forKey:_elementName]; >>> } >>> // just a regular node. >>> else { >>> [resultDict setValue:_elementText forKey:_elementName]; >>> } >>> return resultDict; >>> } >> >> If you don't want nodes stored in an array, then don't use >>NSMutableArray. >> >> I think you need to step back from the coding and do a better analysis. >> At each step of the logical analysis, given a type of XML node as >>input, write down exactly what actions should occur for the desired >>output. Don't write code, just write down brief action descriptions. >> >> For example, I see no arrays in your desired output, so there shouldn't >>be any need for creating an array. If you don't create an array for >>children, analyze what is needed instead. >> >> You could also benefit by doing an analysis (i.e. write action >>descriptions) of the code you have now. When you get to the part that >>says "Create array. Fill it with every child", think about what that >>means. >> >> FWIW, this isn't a Cocoa problem, it's a logic problem. Get the logic >>right first, then the Cocoa code should be plain. >> >> -- GG >> >> _______________________________________________ >> >> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) >> >> Please do not post admin requests or moderator comments to the list. >> Contact the moderators at cocoa-dev-admins(at)lists.apple.com >> >> Help/Unsubscribe/Update your Subscription: >> >>http://lists.apple.com/mailman/options/cocoa-dev/apple.lists%40gestosoft. >>com >> >> This email sent to apple.li...@gestosoft.com > >_______________________________________________ > >Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > >Please do not post admin requests or moderator comments to the list. >Contact the moderators at cocoa-dev-admins(at)lists.apple.com > >Help/Unsubscribe/Update your Subscription: >http://lists.apple.com/mailman/options/cocoa-dev/garywade%40desisoftsystem >s.com > >This email sent to garyw...@desisoftsystems.com _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com