what i’m trying to achieve is the following. I’ve got a MySQL database and using SimpleXML in a PHP script to convert there entries to XML. So i’ve got a ‘id’, ‘department’, ‘name’, ‘tel’ and an ’email’ field. PHP parses it to this output (don’t know if this is the most logical output, but seems legit) (primary unique key ‘id’ has been left out)
<?xml version="1.0" encoding="UTF-8" ?>
<entries>
<entry>
<department>DeptA</department>
<name>NameA</name>
<tel>0000-111111</tel>
<email>namea@abc.com</email>
</entry>
<entry>
<department>DeptB</department>
<name>NameB1</name>
<tel>0000-2222222</tel>
<email>nameb1@abc.com</email>
</entry>
<entry>
<department>DebtB</department>
<name>NameB2</name>
<tel>0000-2222223</tel>
<email>nameb2@abc.com</email>
</entry>
more entry
</entries>
So i have three Views in Xcode. First View (MasterViewController) should report the departments as unique values. In above XML DebtA and DebtB. (more in actual XML) and list them in a Table View. Tried do do this with NSSlist *uniqueArray (etc) without success. Then when clicking on a department in MasterViewController you go the DebtViewController which lists all the names of the employees working in that particular department. So for DebtB that should be NameB1 and NameB2. (DebtA only NameA). Last view is a DetailViewController, on which detailinformation is listed for that particular name clicked in DebtViewController. Details like, the Name, Tel and Email. (Maybe a picture when i get the hang of it)
So concretely, the thing is i’ve been struggling with this for quite a few days and want to know what the best route is i should take. Is the XML i’m currently using any good for the task i want to achieve ? should i group the departments together in XML before parsing in xcode ? or can that be done afterwards just as well ? If so, pls suggest some pointers.
You’re on the right track– based on what you’re trying to do, I would recommend formatting the xml file something like this:
It’s a bit more complex than what you’ve got so far, but this allows you to read the contents of the file directly into an NSDictionary object by doing something like this:
Once you’ve done that, you can get a list of strings representing the department names by doing this:
And this line will get you a list of all the employees in DeptB:
The list of employees is returned in the form of an array of NSDictionary objects, each of which has values stored for the keys @”Name”, @”tel”, and @”email.”
As you can see, it does get more than a little complicated, but trust me– once you get the hang of it, it becomes really easy to store and read really complex xml data. MacOS even has a Property List Editor that provides a nice interface for creating xml files of this type that can be read by XCode.
I recommend this link– it was really helpful for me when I was learning to do this type of thing:
https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/PropertyLists/Introduction/Introduction.html#//apple_ref/doc/uid/10000048-CJBGDEGD