Nested XML -> CoreData
Nested XML -> CoreData
- Subject: Nested XML -> CoreData
- From: Koen van der Drift <email@hidden>
- Date: Tue, 15 May 2012 10:29:07 -0400
I'm parsing a large XML file using NSXMLParser (OS X) and part of the
nested structure is similar to this:
<Person>
...
...
<PhoneNumbers>
<PhoneNumber>
<PhoneNumberType>Home</PhoneNumberType>
<PhoneNumberValue>123-555-1234</PhoneNumberValue>
</PhoneNumber>
<PhoneNumber>
<PhoneNumberType>Work</PhoneNumberType>
<PhoneNumberValue>345-555-6612</PhoneNumberValue>
</PhoneNumber>
<PhoneNumber>
<PhoneNumberType>Mobile</PhoneNumberType>
<PhoneNumberValue>222-555-8901</PhoneNumberValue>
</PhoneNumber>
</PhoneNumbers>
...
...
</Person>
In advance I don't know how many phonenumbers there will be, there could be
none, or more than three, and they also may have a different
<PhoneNumberType> (eg 'Second Home'). The obvious thing to do I guess, is
just everytime the parser reaches <PhoneNumbers>, I create an array, and
every time the parser reaches <PhoneNumber> I create a dictionary, fill it
with the type and number and add that to the array when </PhoneNumber> is
reached.
However, the data read with the parser needs to end up in my Core Data
model. Obviously I already created a Person entity, but how do I add the
phone numbers to it? Create a PhoneNumber entity with two attributes? Or
stuff the PhoneNumbers array in an NSData object, and make that an
attribute of the Person entity, and pull out the data when needed? I see
the advantage of the former, in case I want to find out which Persons share
a PhoneNumber (or Address, Car, etc).
I guess my question is, should I make my CoreData model as nested as my XML
file is, with lots of small entities?
Furthermore, converting an XML file into strings, arrays and dictionaries,
and then converting it back to Entities which are stored in an XML
structure in the store seems over complicated to me. Any thoughts on that?
- Koen.
_______________________________________________
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