Greetings.

I'm trying to convert XML file to a plist format.
i am using the event driven method of XMLParser for iOS.

it is currently working to some level but i am having a problem with XMl 
elements all being nested into Dictionaries.


for example the following XML:

<element1>
        <element2> text </element2>
        <element3>
                <element4> text </element4>
                <element5> text </element5>
        </element3>
        <element6> text </element6>
        <element7> text </element7>
</element1>

Would result in:

<plist version="1.0">
<dict>
        <key>element1</key>
        <array>
                <dict>
                        <key>element2</key>
                        <string>text</string>
                </dict>
                <dict>
                        <key>element3</key>
                        <array>
                                <dict>
                                        <key>element4</key>
                                        <string>text</string>
                                </dict>
                                <dict>
                                        <key>element5</key>
                                        <string>text</string>
                                </dict>
                        </array>
                </dict>
                <dict>
                        <key>element6</key>
                        <string>text</string>
                </dict>
                <dict>
                        <key>element7</key>
                        <string>text</string>
                </dict>
        </array>
</dict>
</plist>

Which is completely insane to manage.
What i would preffer is something along these lines.

<plist version="1.0">
<dict>
        <key>element1</key>
        <dict>
                <key>element2</key>
                <string>text</string>
                <key>element3</key>
                <dict>
                        <key>element4</key>
                        <string>text</string>
                        <key>element5</key>
                        <string>text</string>
                </dict>
                <key>element6</key>
                <string>text</string>
                <key>element7</key>
                <string>text</string>
        </dict>
</dict>
</plist>


every node object in the link list has a procedure that returns it's content 
and pulls the content if it's child objects,
but i'm having a hard time figuring out the proper way to do it ti achieve the 
preferred plist format.

- (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;
}


would anyone be really kind and point out where I'm really missing the point... 
I've been on thins little puzzle for quite some time now.
thank you for any and all advice.


best regards.
Sandro._______________________________________________

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

Reply via email to