Note that there are some explanatory texts on larger screens.

plurals
  1. POextract data from NSMutableArray
    text
    copied!<p>In my application i parse a xml from which I get a list of items (hotels and restaurants) that i put into array "listElements"; I need to get from this array, another array that will contain only the particular elements (hotels only) and then I need to get from this array, three array that will contain hotels according to stars(array5starhotel, array4starhotel,array3starhotel). How can do this? This is the code I used for parsing(I used TBXML):</p> <pre><code>- (void)loadCategories { // instantiate an array to hold categories objects listCategories = [[NSMutableArray alloc] initWithCapacity:100]; tbxml = [[TBXML tbxmlWithXMLFile:@"Molise.xml"] retain]; // Obtain root element TBXMLElement * root = tbxml.rootXMLElement; // if an author element was found if (root) { //search for the first category element within the root element's children TBXMLElement * category = [TBXML childElementNamed:@"category" parentElement:root]; // if a category element was found while (category != nil) { // instantiate a category object Category * aCategory = [[Category alloc] init]; // get the name attribute from the category element aCategory.name = [TBXML valueOfAttributeNamed:@"name" forElement:category]; // search the category's child elements for a "element" element TBXMLElement * element = [TBXML childElementNamed:@"element" parentElement:category]; // if a "element" element was found while (element != nil) { // instantiate a "element" object Element * aElement = [[Element alloc] init]; // extract the attributes from the "element" element aElement.title = [TBXML valueOfAttributeNamed:@"title" forElement:element]; aElement.address = [TBXML valueOfAttributeNamed:@"address" forElement:element]; aElement.stars =[TBXML valueOfAttributeNamed:@"stars" forElement:element]; // add the "element" object to the category's listElements array and release the resource [aCategory.listElements addObject:aElement]; [aElement release]; // find the next sibling element named "element" element = [TBXML nextSiblingNamed:@"element" searchFromElement:element]; } // add our category object to the listCategories array and release the resource [listaCategories addObject:aCategory]; [aCategory release]; // find the next sibling element named "category" category = [TBXML nextSiblingNamed:@"category" searchFromElement:category]; } [tbxml release]; } </code></pre>
 

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