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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:14:56+00:00 2026-06-12T07:14:56+00:00

I have an NSXMLParser , which is parsing an XML file, using Apple’s implementation

  • 0

I have an NSXMLParser, which is parsing an XML file, using Apple’s implementation of event-driven XML handling.

I have it setup correctly, but when I get to the actual parsing, it goes over the same element twice as it parses through.

My code looks like this:

AppDelegate *myApp = (AppDelegate*)[[UIApplication sharedApplication] delegate];
NSData *tempData = [myApp.stringDetails dataUsingEncoding:NSUTF8StringEncoding];
NSString *textFields = [NSString string];
NSXMLParser *parser = [[NSXMLParser alloc]initWithData:tempData];
[parser setDelegate: self];
if ([parser parse]!= YES) {
    NSLog(@"%@", parser.parserError.description);
}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName     namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
    textFields = elementName;
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
    if ([textFields isEqualToString:@"firstName"]) {
        [firstName setText:string];
        NSLog(@"first name is %@", string);
        return;
    }
    if ([textFields isEqualToString:@"lastName"]) {
        [lastName setText:string];
        NSLog(@"last name is %@", string);
        return;
    }
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
    return;
}

The XML document i’m parsing looks like this:

<details>
<firstName>tester</firstName>
    <lastName>testingson</lastName>
    <address>
    <street1>123 Main St.</street1>
    <street2></street2>
    <city>Anywhere</city>
    <state>BC</state>
    <country></country>
    <postalCode>A0A0B0</postalCode>
</address>
<company>TEST</company>
<email>testing@test.com</email>
<cabbieNo>TEST</cabbieNo>
<driversLicense>TEST</driversLicense>
<plateNo>TEST</plateNo> 
<services>
    <taxi>1</taxi>
    <ladies>1</ladies>
    <limo>1</limo>
    <handicap>1</handicap>
</services>
</details>

Strangely, my debug logs like this:

2012-10-01 15:36:35.742 myAPP[9974:c07] first name is tester
2012-10-01 15:36:35.743 myAPP[9974:c07] first name is
2012-10-01 15:36:35.743 myAPP[9974:c07] last name is testingson
2012-10-01 15:36:35.744 myAPP9974:c07] last name is 

As you can see, it looks through each element twice, but then on the second time, string is empty (which shouldn’t happen..in fact there shouldn’t even be a second foundCharacters event). Do you guys have any idea why?

Thanks!

  • 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-12T07:14:58+00:00Added an answer on June 12, 2026 at 7:14 am

    You should get your Element result in didEndElement

    Here is example

    https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/XMLParsing/Articles/HandlingElements.html

    In - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string

    You should append string(found characters) eg:

    - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
        if (!currentStringValue) {
            // currentStringValue is an NSMutableString instance variable
            currentStringValue = [[NSMutableString alloc] initWithCapacity:50];
        }
        [currentStringValue appendString:string];
    }
    

    Hope this will be helpful to you.

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

Sidebar

Related Questions

I have the following xml file which I am parsing using NSXMLParser : <geometry
I have an xml file which i create myself. <?xml version='1.0' encoding='utf-8' ?> <Root>
I am using NSXMLParser to parse a remote XML file to display information in
I have some code which fetches an XML file from a URL and then
I have got an application, that is getting data via XML-files. During the parsing-part
I have a few views which parse xml downloaded from the internet. The instruments
I have a class which parse an XML feed. In that class I have
I have implemented the NSXMLParserDelegate protocol and appear to be successfully parsing XML with
Let's say I'm using NSXMLParser to load a level (stored as an XML document,
I got xml file which is about 400 mb. in size. I want to

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.