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 6148883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:21:25+00:00 2026-05-23T19:21:25+00:00

I’m using the TBXML Parser to parse some big xml file. The xml file

  • 0

I’m using the TBXML Parser to parse some big xml file. The xml file is structured like this:

<Products>
<Category>
<product></product>
</Category>
</Products>

And this is the code which i’am using to parse the xml:

- (void)loadURL {
    // Load and parse an xml string
    Products *product = [[Products alloc] init];
    tbxml = [[TBXML alloc] initWithURL:[NSURL URLWithString:@"SOMELINK"]];

    // If TBXML found a root node, process element and iterate all children

    // Obtain root element
    TBXMLElement * root = tbxml.rootXMLElement;

    // if root element is valid
    if (root) {
        // search for the first category element within the root element's children

        TBXMLElement *Category = [TBXML childElementNamed:@"Category" parentElement:root];

        product.category = [TBXML valueOfAttributeNamed:@"DisplayName" forElement:Category];
        NSLog(@"%@", product.category);
        // if an author element was found

        while ([[TBXML valueOfAttributeNamed:@"DisplayName" forElement:Category] isEqualToString:@"Dames"]) {





            product.category = [TBXML valueOfAttributeNamed:@"DisplayName" forElement:Category];

            TBXMLElement *xmlProduct = [TBXML childElementNamed:@"Product" parentElement:Category];


            while (xmlProduct != nil) {
                Products *product = [[Products alloc] init];

                // extract the title attribute from the book element
                product.productId = [TBXML valueOfAttributeNamed:@"Id" forElement:xmlProduct];

                product.material = [TBXML valueOfAttributeNamed:@"Material" forElement:xmlProduct];

                product.color = [TBXML valueOfAttributeNamed:@"Color" forElement:xmlProduct];

                product.heel = [TBXML valueOfAttributeNamed:@"Heel" forElement:xmlProduct];

                product.lining = [TBXML valueOfAttributeNamed:@"Lining" forElement:xmlProduct];

                product.subcategory = [TBXML valueOfAttributeNamed:@"DisplayName" forElement:xmlProduct];


                NSString * price = [TBXML valueOfAttributeNamed:@"Price" forElement:xmlProduct];



                // if we found a price
                if (price != nil) {
                    // obtain the price from the book element
                    product.price = [NSNumber numberWithFloat:[price floatValue]];
                }



                // add the book object to the dames array and release the resource
                [dames addObject:product];
                [product release];


                // find the next sibling element named "xmlProduct"
                xmlProduct = [TBXML nextSiblingNamed:@"Product" searchFromElement:xmlProduct];
            }




            // find the next sibling element named "Category"
            Category = [TBXML nextSiblingNamed:@"Category" searchFromElement:Category];
        }



        while ([[TBXML valueOfAttributeNamed:@"DisplayName" forElement:Category] isEqualToString:@"Accessoires"]) {





            product.category = [TBXML valueOfAttributeNamed:@"DisplayName" forElement:Category];

            TBXMLElement *xmlProduct = [TBXML childElementNamed:@"Product" parentElement:Category];


            while (xmlProduct != nil) {
                Products *product = [[Products alloc] init];


                product.productId = [TBXML valueOfAttributeNamed:@"Id" forElement:xmlProduct];

                product.material = [TBXML valueOfAttributeNamed:@"Material" forElement:xmlProduct];

                product.color = [TBXML valueOfAttributeNamed:@"Color" forElement:xmlProduct];

                product.subcategory = [TBXML valueOfAttributeNamed:@"DisplayName" forElement:xmlProduct];

                product.heel = [TBXML valueOfAttributeNamed:@"Heel" forElement:xmlProduct];

                product.lining = [TBXML valueOfAttributeNamed:@"Lining" forElement:xmlProduct];


                NSString * price = [TBXML valueOfAttributeNamed:@"Price" forElement:xmlProduct];



                // if we found a price
                if (price != nil) {
                    // obtain the price from the book element
                    product.price = [NSNumber numberWithFloat:[price floatValue]];
                }




                [tassen addObject:product];
                [product release];



                xmlProduct = [TBXML nextSiblingNamed:@"Product" searchFromElement:xmlProduct];
            }



            // find the next sibling element named "Category"
            Category = [TBXML nextSiblingNamed:@"Category" searchFromElement:Category];

        }


        }
    }

In total I have 4 categories (Cut out the middle 2 of them because of irrelevant in the code above). All works fine when I parse the first 3 categories, but as soon I get to the last there is happening something strange.

The Category = [TBXML nextSiblingNamed:@"Category" searchFromElement:Category]; line is going to search for a new category, but since there isn’t one, it will return null. I would say the parser if finished, but at this moment the parser crashes and gives an EXC_BAD_ACCESS in the TBXML.M file (from the tbxml api) on the following code:

TBXMLAttribute * attribute = aXMLElement->firstAttribute;

I have no clue why, but maybe someone here sees it right away… Any help would be appreciated!

Thnx in advance!

  • 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-23T19:21:26+00:00Added an answer on May 23, 2026 at 7:21 pm

    The problem is solved:

    This code gave the bad access:

     while ([[TBXML valueOfAttributeNamed:@"DisplayName" forElement:Category] isEqualToString:@"Accessoires"])
    

    Resolved it with while (category !=nil) and it worked

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

Sidebar

Related Questions

I have some data like this: 1 2 3 4 5 9 2 6
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
i want to parse a xhtml file and display in UITableView. what is the
I'm parsing an XML file, the creators of it stuck in a bunch social
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported

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.