• 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
XML to Plist
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

XML to Plist


  • Subject: XML to Plist
  • From: Sandro Noël <email@hidden>
  • Date: Tue, 28 Dec 2010 12:30:13 -0500

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

  • Prev by Date: Re: Memory management about async object
  • Next by Date: Re: XML to Plist
  • Previous by thread: Re: Runtime Error: Incompatable applications
  • Next by thread: Re: XML to Plist
  • Index(es):
    • Date
    • Thread