Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding NSArrays to NSDictionary
    primarykey
    data
    text
    <p>I am parsing a XML file with a format of:</p> <p>**NOTE: This is a very simplified version of the XML. There are 11 divisions, and 87 departments total</p> <pre><code>&lt;division&gt; &lt;name&gt; Sciences &lt;/name&gt; &lt;departments&gt; &lt;department&gt; &lt;name&gt; Computer Science &lt;/name&gt; &lt;/department&gt; &lt;department&gt; &lt;name&gt; Biology &lt;/name&gt; &lt;/department&gt; &lt;department&gt; &lt;name&gt; Chemistry &lt;/name&gt; &lt;/department&gt; &lt;/department&gt; &lt;/division&gt; </code></pre> <p>What I am hoping to do is display this info in a UITableView, with Division names as the Sections, and the department names within each appropriate section. </p> <p>I have a NSDictionary called divisionDict which I want to store NSArrays for each division; containing the departments. I also have a NSMutableArray called departmentArray, which contains each of the departments. So essentially, I want a divisionDict filled with departmentArrays.</p> <p>Here is my code for parsing the XML, which works perfect, I am just having trouble storing separate arrays in the dictionary. When it goes through the parse now, and I try to print out the elements in the array with key "Sciences", it prints the departments for every division, not just the Sciences.</p> <pre><code>if(node_divisions) { node_division = [TBXML childElementNamed:@"division" parentElement:node_divisions]; while (node_division) { node_divisionName = [TBXML childElementNamed:@"name" parentElement:node_division];]; node_departments = [TBXML childElementNamed:@"departments" parentElement:node_division]; node_department = [TBXML childElementNamed:@"department" parentElement:node_departments]; divisionName = [TBXML textForElement:node_divisionName]; while(node_department) { node_departmentName = [TBXML childElementNamed:@"name" parentElement:node_department]; departmentName = [TBXML textForElement:node_departmentName]; //add the department name to the array [departmentArray addObject:departmentName]; node_department = node_department-&gt;nextSibling; } //add the departmentArray to the dictionary, using the division name as the key [divisionDict setObject:departmentArray forKey:divisionName];; node_division = node_division-&gt;nextSibling; } } </code></pre> <p>Any help is greatly appreciated!!! I know its something simple I am missing probably but I have been looking at this for too many hours now and I just can't see it. If you need any other info, just let me know, I tried to explain everything in detail.</p> <p>Also, here is a picture that hopefully helps show what I am trying to describe: <a href="http://i.stack.imgur.com/a9nSb.png" rel="nofollow">http://i.stack.imgur.com/a9nSb.png</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload