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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:49:17+00:00 2026-06-12T20:49:17+00:00

if([elementName isEqualToString:@EmpWithNameAndID]){ [emps addObject:empObject]; NSLog(@count of emps is : %d,emps.count); self.managedObjectContext = appDelegate.managedObjectContext; EmpWithName

  • 0
if([elementName isEqualToString:@"EmpWithNameAndID"]){
    [emps addObject:empObject];
    NSLog(@"count of emps is : %d",emps.count);

    self.managedObjectContext = appDelegate.managedObjectContext;

    EmpWithName *empWithNameObj = [NSEntityDescription insertNewObjectForEntityForName:@"EmpWithName"
                                                                inManagedObjectContext:self.managedObjectContext];
    if(!self.empObject){
        NSLog(@"Not nil");}
    else {
        NSLog(@"Yo Nil");
    }

    empWithNameObj.empID =self.empObject.empID;//@"123"
    empWithNameObj.empName =self.empObject.empName;//@"ABC"

    NSLog(@"emp object id is: %@",empWithNameObj.empID);
    NSLog(@"emp name is %@",empWithNameObj.empName);


    if(self.managedObjectContext == nil)
    { NSLog(@"S MOC is nil");}
    else {
        NSLog(@"S MOC is Not NIL");
    }

    NSError *error;
    if(![self.managedObjectContext save:&error]){
        NSLog(@"Failed to save the object");
    }
    else {

        NSLog(@"saved object");
    }
    if(error == nil)
    {
        NSLog(@"Good saved");
    }
    else {
        NSLog(@"something went wrong while saving");
    }
}
else {

    if([elementName isEqualToString:@"empName"] || [elementName isEqualToString:@"EmpID"]){

        NSLog(@"Element name is: %@ and its value is : %@ ",elementName,currentElementValue);

        if(!empObject)
        {
            NSLog(@"just empobject not nil");
        }
        else {
            NSLog(@"its nil.empobject");
        }


        if(!self.empObject){
            NSLog(@"Not nil");}
        else {
            NSLog(@"Yo Nil");
        }

        [self.empObject setValue:currentElementValue forKey:elementName];

            if([elementName isEqualToString:@"empName"]){
            NSLog(@"empName stored is %@", self.empObject.empName);
        }
        if([elementName isEqualToString:@"EmpID"]){
            NSLog(@"EmpID value stored is %@",self.empObject.empID);
        }
        currentElementValue = nil;
    }
}

So all the above code is in didEndElement of NSXMLParser.
In else part at the end of the code just before i set currentElementValue as nil I have two if conditions.So when the elementName is empName it logs this to the output “empName stored is (null)”. But before that i have this log statement “Element name is: empName and its value is :

ABC". 

So my question is if it knows the element name and its value why is it not saving its values. Why are they logging as nulls? Please help. If more information is needed please ask. 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-12T20:49:18+00:00Added an answer on June 12, 2026 at 8:49 pm

    Well i figured out a solution. I dont know if it is correct or not but i got what i wanted. What i did was in the else block instead of saving to self.empObject i made use of a NSMutabledictionary i created in initParser and added the values to them. Then in the if block used that dictionary to retrieve the values by key-name (because i already know the key-names) and assigned them to empNameWithObj and did removeAllObjects on dictionary. Remaining procedure is same. It worked.

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

Sidebar

Related Questions

The Code: ... else if ([elementName isEqualToString:@photo]) { NSLog(@Trying to add photo); NSLog(@Prev: %d,[currentItem.photoList
I'm parsing this line: <type>branch</type> with this code in didEndElement if ([elementName isEqualToString:@type]) {
I have model: [XmlRoot(ElementName = event, IsNullable=true)] public class Event { public int id
Model for xmlconverter: [XmlRoot(ElementName = location, IsNullable = true)] public class location { public
Has anybody else noticed that Bindings with ElementName do not resolve correctly for MenuItem
Here's the class im trying to store [Serializable] [XmlRoot(ElementName = Database, IsNullable = false,
I have a class Image implementing ISerializable : [Serializable] [XmlRoot(ElementName = IMAGE)] [TypeConverter(typeof(ImageTypeConverter))] public
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict { if( [elementName
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ //currentElenet is NSString
I am not getting that how to differentiate same element name for eg City,Area

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.