Re: XML to Plist
Re: XML to Plist
- Subject: Re: XML to Plist
- From: Greg Guerin <email@hidden>
- Date: Tue, 28 Dec 2010 11:10:59 -0700
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 (email@hidden)
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:
This email sent to email@hidden