开发者

xCode: convert XML file to CoreData model

I need some advice on how to create a coredata model that has Departments, Groups and People.

I have this working using an XML file, but I'd like to make this a proper SQLite DB.

A subset of the XML file is below..

The rules are each Dept can have multiple Groups and each group can have multiple people. Once again, I would appreciate any advice..

(Apologies for the long code post)

    <key>itemChildren</key>

        <dict>
            <key>itemChildren</key>

                <dict>
                    <key>itemChildren</key>

                        <dict>
                            <key>itemTitle</key>
                            <string>Person1</string>
                            <key>itemSubTitle</key>
                            <string>Person1Detail</string>
                        </dict>
                        <dict>
                            <key>itemTitle</key>
                            <string>Person2</string>
                        </dict>
                        <dict>
                        Person x........
                        </dict>
                        <dict>
                            <key>itemTitle</key>
                            <string>Infinitive</string>
                        </dict>

                    <key>itemTitle</key>
                    <string>Group1</string>
                    <key>itemSubTitle</key>
                    <string>Group1 Detail</string>
                </dict>
                <dict>
                    <key>itemChildren</key>

                        <dict>
                            <key>itemTitle</key>
                            <string>Person1</string&开发者_StackOverflow社区gt;
                            <key>itemSubTitle</key>
                            <string>Person1Detail</string>
                        </dict>
                        <dict>
                            <key>itemTitle</key>
                            <string>Person2</string>
                        </dict>
                                            </array>
                    <key>itemTitle</key>
                    <string>Group2</string>
                    <key>itemSubTitle</key>
                    <string>Group2 Detail</string>
                </dict>
                <dict>
                    <key>itemChildren</key>

                        <key>itemTitle</key>
                            <string>Person1</string>
                            <key>itemSubTitle</key>
                            <string>Person1Detail</string>
                        <dict>
                            <key>itemTitle</key>
                            <string>Person2</string>
                        </dict>
                        <dict>
                            <key>itemTitle</key>
                            <string>Person3</string>
                        </dict>
                                    </array>
                    <key>itemTitle</key>
                    <string>Groupx</string>
                    <key>itemSubTitle</key>
                    <string>Groupx Detail</string>

                 ........

                </dict>

            <key>itemTitle</key>
            <string>Dept1</string>
            <key>itemSubTitle</key>
            <string>Dept1Detail</string>
        </dict>
        <dict>
            <key>itemChildren</key>

                <dict>
                    <key>itemChildren</key>
                    <array>
                        <dict>
                            <key>itemTitle</key>
                            <string>Person1</string>
                            <key>itemSubTitle</key>
                            <string>Person1Detail</string>
                .....
            <key>itemTitle</key>
            <string>Dept2</string>
            <key>itemSubTitle</key>
            <string>Dept2Detail</string>
        </dict>
        ........
            <key>itemTitle</key>
            <string>Dept3</string>
            <key>itemSubTitle</key>
            <string>Dept3Detail</string>
        </dict>

</dict>


Unless I'm missing something, at least conceptually your database schema should be pretty simple.

I would start with the main entities required for your model: Person, Group and Department. They can each have their own individual properties as per normal.

Once you have the entities and properties created, you need to establish the relationships between them.

Based on what you said this is how I suggest you approach it, including the respective reverse relationships:

Person<<------>>Group (many-to-many) meaning one Person can be in many Groups(assumption?) and one Group can have many Person instances

Person<<------->Department (many-to-one) meaning one Person can be in one Department and one department can have many 'persons'

Group<<------->Department (many-to-one) or (many-to-many) if you want to allow groups to be part of many departments.


I apologize for the delay in responding. Life happened.. What I came up with was a db with two tables - for argument, verbs and persons.

The schema looks like this:

xCode: convert XML file to CoreData model

It's not as elegant as I would like as there is repetitive persons, but, it seems to work.

Again, sorry for the delay.

David

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜