• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: XML to Plist
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: XML to Plist


  • Subject: Re: XML to Plist
  • From: "Gary L. Wade" <email@hidden>
  • Date: Tue, 28 Dec 2010 10:41:13 -0800
  • Thread-topic: XML to Plist

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" <email@hidden> 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 (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:
>>
>>com
>>
>> This email sent to email@hidden
>
>_______________________________________________
>
>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:
>s.com
>
>This email sent to email@hidden


_______________________________________________

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

References: 
 >Re: XML to Plist (From: Sandro Noël <email@hidden>)

  • Prev by Date: Re: XML to Plist
  • Next by Date: Re: XML to Plist
  • Previous by thread: Re: XML to Plist
  • Next by thread: Re: XML to Plist
  • Index(es):
    • Date
    • Thread