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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:59:43+00:00 2026-06-07T21:59:43+00:00

I am parsing an xml file , it works and show me the data

  • 0

I am parsing an xml file , it works and show me the data parsed in the console( for example : processing value for Speller …), but they aren’t added to the msmutablearray users. Here is some code. Where is the problem ? help please :

- (MyData *) initXMLParser {
    [super init];
    // init array of user objects 
    users = [[NSMutableArray alloc] init];
    return self;
}


- (void)parser:(NSXMLParser *)parser 
didStartElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI 
 qualifiedName:(NSString *)qualifiedName 
    attributes:(NSDictionary *)attributeDict 
{

    if ([elementName isEqualToString:@"user"]) {
        NSLog(@"user element found – create a new instance of User class...");
        user = [[User alloc] init];

    }
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
    if (!currentElementValue) {
        // init the ad hoc string with the value     
        currentElementValue = [[NSMutableString alloc] initWithString:string];
    } else {
        // append value to the ad hoc string    
        [currentElementValue appendString:string];
    }
    NSLog(@"Processing value for : %@", string);
}  

- (void)parser:(NSXMLParser *)parser 
 didEndElement:(NSString *)elementName
  namespaceURI:(NSString *)namespaceURI 
 qualifiedName:(NSString *)qName 
{

    if ([elementName isEqualToString:@"users"]) {
        // We reached the end of the XML document
        return;
    }

    if ([elementName isEqualToString:@"user"]) {

        if ([elementName isEqualToString:@"userName"]) {
                [[self user] setUserName:currentElementValue];

            }
            if ([elementName isEqualToString:@"firstName"]) {
                [[self user] setFirstName:currentElementValue];

            }

            if ([elementName isEqualToString:@"lastName"]) {
                [[self user] setLastName:currentElementValue];

            }

        [users addObject:user];
        /*comboarray = [[users arrayForKey:@"ComboBoxValues"]
                      sortedArrayUsingSelector:@selector(compare:)];*/

        // release user object
        [user release];
        user = nil;

    } else {

        [user setValue:currentElementValue forKey:elementName];
           }

    [currentElementValue release];
    currentElementValue = nil;
}
-(BOOL)parseDocumentWithData:(NSData *)data {
    //NSString * filePath = [[NSBundle mainBundle] pathForResource:@"Users" ofType:@"xml"];
    //data = [NSData dataWithContentsOfFile:filePath];

    if (data == nil)
        return NO;

    // this is the parsing machine
    NSXMLParser *xmlparser = [[NSXMLParser alloc] initWithData:data];

    // this class will handle the events
    [xmlparser setDelegate:self];
    [xmlparser setShouldResolveExternalEntities:NO];

    // now parse the document
    BOOL ok = [xmlparser parse];
    if (ok == NO)
        NSLog(@"error");
    else
        NSLog(@"OK");

    [xmlparser release];
    return ok;
}


- (void) dealloc {

    [currentElementValue release];
    [super dealloc];
}
  • 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-07T21:59:45+00:00Added an answer on June 7, 2026 at 9:59 pm

    This seems to be the problematic part of your code

    - (MyData *) initXMLParser {
        [super init]; // change to self = [super init];
        // init array of user objects 
        users = [[NSMutableArray alloc] init];
        return self;
    }
    

    You are not initializing self with the value of [super init];

    And add [users release]; line to your dealloc call unless you release it elsewhere

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

Sidebar

Related Questions

I am parsing xml file data from an url. All works great when device
I know, that this way of dtd validation before parsing a xml file works:
I am using the following code by the Android-people-XMLParsing example for parsing XML file
I have a value I am parsing from an xml file that I need
I am parsing an xml file , and trying to show in a table
I'm developing an application that uses the xml parsing. Everything works wing perfection but
I am parsing xml file from server using xmlParser in Android. When i print
I've used following code for parsing XML file in c++. http://www.codeproject.com/Articles/176236/Parsing-an-XML-file-in-a-C-C-program . Now I
When parsing an xml file in android, I'm doing like this: try { InputStream
I am parsing a XML file supplied by some software. Part of the parsing

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.