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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:46:46+00:00 2026-06-13T23:46:46+00:00

I’m trying to parse a REST response which is in XML. The interesting thing

  • 0

I’m trying to parse a REST response which is in XML. The interesting thing about the response is that multiple nodes have the same name. I’m looking for a simple way to parse this data in iOS. Here’s a sample:

<Report name="BalanceSheet">
<ColDesc><ColTitle>AccountType</ColTitle><ColType>ids_String</ColType></ColDesc>
<ColDesc><ColTitle>Amount</ColTitle><ColType>ids_Amount</ColType></ColDesc>
<Data>
<DataRow>
<ColData>Checking/Savings</ColData>
<ColData>12345345</ColData>
</DataRow>
<DataRow>
<ColData>Accounts Receivable</ColData>
<ColData>674532</ColData>
</DataRow>
<DataRow>
<ColData>Other Current Assets</ColData>
<ColData>423546</ColData>
</DataRow>
<DataRow>
<ColData>Fixed Assets</ColData>
<ColData>63545534</ColData>
</DataRow>
<DataRow>
<ColData>Other Assets</ColData>
<ColData>325465</ColData>
</DataRow>
<DataRow>
<ColData>Accounts Payable</ColData>
<ColData>653653</ColData>
</DataRow>
<DataRow>
<ColData>Other Current Liabilities</ColData>
<ColData>910596.75</ColData>
</DataRow>
<DataRow>
<ColData>Long Term Liabilities</ColData>
<ColData>553797.26</ColData>
</DataRow>
<DataRow>
<ColData>Equity</ColData>
<ColData>45363</ColData>
</DataRow>
</Data>
</Report>

I have tried using the SMXMLDocument parser as well as tried to convert it to a NSDictionary using XMLReader. The way the XML is structured is just confusing.

Any suggestions?

  • 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-13T23:46:47+00:00Added an answer on June 13, 2026 at 11:46 pm

    I had already written a simple NSXMLParser example earlier today, so I just took that and made it parse the XML you describe.

    Working example project here: https://github.com/erikt/ETParseIntuitSOExample

    The NSXMLParser delegate is what you’re asking for. Here’s the header:

    #import <Foundation/Foundation.h>
    
    @interface ETIntuitParser : NSObject<NSXMLParserDelegate>
    + (NSDictionary *)parseIntuitXML:(NSString *)xml;
    @end
    

    And the implementation:

    #import "ETIntuitParser.h"
    
    @interface ETIntuitParser ()
    @property NSUInteger dataColNumber;
    @property (copy,nonatomic) NSString *dataKey;
    @property (strong,nonatomic) NSMutableString *currentElementValue;
    @property (strong,nonatomic) NSMutableDictionary *resultDict;
    @end
    
    @implementation ETIntuitParser
    
    + (NSDictionary *)parseIntuitXML:(NSString *)xml {
        ETIntuitParser *intuitParser = [[ETIntuitParser alloc] init];
        NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:[xml dataUsingEncoding:NSUTF8StringEncoding]];
        [xmlParser setDelegate:intuitParser];
        BOOL success = [xmlParser parse];
    
        if (success) {
            return [NSDictionary dictionaryWithDictionary:intuitParser.resultDict];
        } else {
            NSLog(@"Error parsing login information");
            return nil;
        }
    }
    
    #pragma mark - NSXMLParserDelegate
    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
    {
        if ([elementName isEqualToString:@"Report"]) {
            if (!self.resultDict) {
                self.resultDict = [NSMutableDictionary dictionary];
            }
            return;
        }
    }
    
    - (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
        if (!self.currentElementValue) {
            self.currentElementValue = [[NSMutableString alloc] initWithString:string];
        } else {
            [self.currentElementValue appendString:string];
        }
    }
    
    - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
    {
    
        if ([elementName isEqualToString:@"DataRow"]) {
            self.dataColNumber = 0;
        }
    
        if ([elementName isEqualToString:@"ColData"]) {
            NSString *trimmedValue = [self.currentElementValue stringByTrimmingCharactersInSet:
                                      [NSCharacterSet whitespaceAndNewlineCharacterSet]];
    
            if (self.dataColNumber == 0) {
                self.dataKey = trimmedValue;
                self.dataColNumber++;
            } else {
                [self.resultDict setObject:trimmedValue forKey:self.dataKey];
            }
    
        }
    
        self.currentElementValue = nil;
    }
    @end
    

    I just printed out the resulting dictionary with NSLog (in the viewDidLoad in the view controller no less … ) and the result is:

    2012-11-07 00:21:22.409 ETParseIntuitSOExample[66941:c07] {
        "Accounts Payable" = 653653;
        "Accounts Receivable" = 674532;
        "Checking/Savings" = 12345345;
        Equity = 45363;
        "Fixed Assets" = 63545534;
        "Long Term Liabilities" = "553797.26";
        "Other Assets" = 325465;
        "Other Current Assets" = 423546;
        "Other Current Liabilities" = "910596.75";
    }
    

    I don’t know if you need the column header information from the XML structure, but that should be easy for you to add.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I'm trying to select an H1 element which is the second-child in its group
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from

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.