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

  • SEARCH
  • Home
  • 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 8097995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:56:13+00:00 2026-06-05T21:56:13+00:00

I have a file: <xml> <component>something <system>somethingDeeper <value>somethingDeepest</value> </system> </component> <component>somethinfDifferent <value>somethingDifferentDeeper</value> </component> <value>somethingNew</value>

  • 0

I have a file:

<xml>
    <component>something
        <system>somethingDeeper
            <value>somethingDeepest</value>
        </system>
    </component>

    <component>somethinfDifferent
        <value>somethingDifferentDeeper</value>
    </component>

    <value>somethingNew</value>
</xml>

So I want to distinguish what is inside another tag (ex. <system>) what is not. How to do this with NSXMLParser? I currently use BOOL ivar’s but this is a lot of tags and this is not as elegant as I want it to be. I know that NSXMLParser is a SAX parser and I understand that.

In above example I will be enter to didEndElement method three times with:
elementName equal value Is there a more elegant way to distinguish what entry was from <component> tag above what not?

  • 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-06-05T21:56:15+00:00Added an answer on June 5, 2026 at 9:56 pm

    You could keep an array of tag names you are currently within

    NSMutableArray *tagNameStack;
    

    Each time you enter a new element you add it to this array. Each time you leave you remove it again. i.e.

    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
        [tagNameStack addObject:elementName];
    
        // Your code here
    }
    

    and

    - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
        // Your code here
    
        [tagNameStack removeLastObject];
    }
    

    So, when you are parsing somethingDeepest your tagNameStack array would be

    @"xml", @"component", @"system", @"value"
    

    You can use this stack to decide where you are in the xml i.e.

    - (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
    
        if ([tagNameStack containsObject:@"system"]) {
            // Deal with the value inside the system tag
        } else if ([tagNameStack containsObject:@"component"]) {
            // Deal with the value inside the component tag
        } else {
            // This must be the value inside the XML tag
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have custom component that I can place in my layout file (XML) for
I have written xml file which contains html tags as element like <component> <input
i have xml file that looks like this: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE pointList SYSTEM
My main Spring Configuration XML file specifies something like this: <context:component-scan base-package=com.application /> The
I have an XML file with the following structure: <Products> <Product name=MyProduct1> <Components> <Component
I'm attempting to remove Component elements from the XML below that have File children
I have the following text in a file called build.xml: component.rollup=true component.rollup.modules.buildfiles=io-base.xml, io-form.xml, io-xdr.xml
I want to have an access to another XML file in an inner class
I have a file xml as this: <data> <first> <city> city </city> <people> 400
i have a file Accelerator.xml <?xml version=1.0 encoding=UTF-8?> <os:openServiceDescription xmlns:os=http://www.microsoft.com/schemas/openservicedescription/1.0> <os:homepageUrl>http://www.sapo.pt</os:homepageUrl> <os:display> <os:name>Find on

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.