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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:56:12+00:00 2026-05-20T11:56:12+00:00

My XML import requires that I check for an existing object before I insert.

  • 0

My XML import requires that I check for an existing object before I insert. In other words I need to hold each record in a temporary managed data object before I determine whether to save it or not. *** NOTE: Please refer to the last answer in this thread:

Is there a way to instantiate a NSManagedObject without inserting it?

I took the approach of the last answer in the link above using insertIntoManagedObjectContext:nil which put the incoming one-record into a temporary object without a context.

Within my import I have two tables: a one-table record and multiple related-many record following right behind it. This works great except that I have related-many records following this.

Right now I’m inserting the many-table records into their own managed object with nil also. The question is when I’m about to save the one record, I also have multiple related many objects I’ve created. How do I save the many records? Can I fetch them from a nil context and loop through them?

Here is the code for the beginning of a new record:

        // Incoming record is for the one table.
    if ([elementName isEqualToString: self.xmlRecordTagDelimiter]) {
        NSEntityDescription *entity = [NSEntityDescription entityForName:self.xmlEntityName inManagedObjectContext:xmlManagedObjectContext];
        self.xmlCurrentRecordTempObject = [[NSManagedObject alloc] initWithEntity:entity insertIntoManagedObjectContext:nil];
        thisTagIsForManyTable = NO;
    }   
    // Incoming record is for the many table.
    if ([elementName isEqualToString: self.xmlManyRecordTagDelimiter]) {
        NSEntityDescription *entity = [NSEntityDescription entityForName:self.xmlRelatedManyEntityName inManagedObjectContext:xmlManagedObjectContext];
        self.xmlCurrentManyRecordTempObject = [[NSManagedObject alloc] initWithEntity:entity insertIntoManagedObjectContext:nil];

        thisTagIsForManyTable = YES;
    }

And the code where I’m about to save a one-table record into a contect:

        [self.managedObjectContext insertObject:self.xmlCurrentRecordTempObject];

        // Store what we imported already.
        if (![self.xmlManagedObjectContext save:&error]) {
                         ...... snip.....
        }

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-05-20T11:56:13+00:00Added an answer on May 20, 2026 at 11:56 am

    It sounds like you’re thinking of a nil context as yet another managed object context. This is not the case. When you pass nil as the context to initWithEntity:insertIntoManagedObjectContext: you are requesting that the created managed object not be inserted into any context. It is not inserted into a managed object context called nil. It is not inserted into any managed object context.

    So, when you ask whether you can fetch your many objects from the nil context, the answer is “no.” This is because there is no nil context.

    However, NSManagedObjects are objects. You could store your many objects in an array and, when you’re about to save, just loop through the array, find the many objects that you want to save, and only insert those into your context.

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

Sidebar

Related Questions

I have the following Python code: import xml.dom.minidom import xml.parsers.expat try: domTree = ml.dom.minidom.parse(myXMLFileName)
Here is my sample code: from xml.dom.minidom import * def make_xml(): doc = Document()
In this situation I am trying to perform a data import from an XML
The XML Schema Part 2 specifies that an instance of a datatype that is
Which XML validation tools can you recommend for both performance and accuracy, each of
I have an XML object (loaded using XMLHTTPRequest 's responseXML ). I have modified
I've been working on a project that requires communication both directions between Java and
This XML file contained archived news stories for all of last year. I was
The XML I'm trying to validate is as follows: <root> <element attribute=foo> <bar/> </element>
An XML attribute declared as xs:boolean can acceptable be true, false, 0 or 1.

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.