Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 949633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:25:57+00:00 2026-05-15T23:25:57+00:00

In my application i parse a xml from which I get a list of

  • 0

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):

- (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];
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T23:25:57+00:00Added an answer on May 15, 2026 at 11:25 pm

    OK, so your code snippet doesn’t do what the question says it does.

    You make an array of categories (listCategories) containing lots of Category objects. Each of these contains a listElements array.

    Assuming that you want the items from the ‘hotels’ category . . .

    // Get the hotels category
    Category *hotelsCategory = nil;
    for (Category *temp in listCategories.each) {
      if ([temp.name isEqualToString:@"hotel"]) {
        hotelsCategory = temp;
        break;
      }
    }
    if (nil == hotelsCategory)
      return NSLog(@"No hotels category found");
    
    // Get the hotels from this category with a 3 or above star rating
    NSMutableArray *array5starhotel = [NSMutableArray array];
    NSMutableArray *array4starhotel = [NSMutableArray array];
    NSMutableArray *array3starhotel = [NSMutableArray array];
    for (Element *element in hotelsCategory.listElements) {
      if ([element.stars isEqualToString:@"5"])
        [array5starhotel addObject:element];
      if ([element.stars isEqualToString:@"4"])
        [array4starhotel addObject:element];
      if ([element.stars isEqualToString:@"3"])
        [array3starhotel addObject:element];
    }
    

    Hope that helps – I’ve had to guess at some stuff because I don’t know what’s in a Category or Element object!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.