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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:52:02+00:00 2026-05-13T16:52:02+00:00

I need some advice how to go about this: 1) I retrieve an XML

  • 0

I need some advice how to go about this:

1) I retrieve an XML from a web server.

2) I want to store all the entities (i.e. Friends) from that XML locally on the device, using Core Data.

3) So I parse the XML and make an Managed Object for every Friend in that XML

4) But I want to make sure that I don’t add one Friend multiple times into the DB. How could I achieve that?

————– my strategy thoughts on this —————-

A) While parsing the XML, I create an Managed Object of the Friend entity as soon as there is a Friend element started. At that point I don’t know which friend it will be, until the NSXMLParser stepped through all the upcoming attributes like firstName, id, etc.; After the End-tag for the Friend element, I have that friend in my Managed Object Context. Then I make an NSFetchRequest to see if that friend is stored already. Problem is, that the new friend is already part of the context, so probably Core Data will return always a match!?

B) I need two different Managed Object Contexts so that the parsed Friends first go into MOC_A, and then I query MOC_B (the actual local store) without that the new parsed friends disturbe my query to the local store. So I can find out if the friend already existed.

C) While parsing a friend from the XML I just create a new Managed Object instance WITHOUT adding it to an Managed Object Context (possible ?!). Later, when the friend is pares completely, I check against Core Data if it is stored. If not, I add it. Otherwise I throw the object away.

D) I need another strategy.

  • 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-13T16:52:02+00:00Added an answer on May 13, 2026 at 4:52 pm

    You should use a new indexed attribute in your Core Data entity to store the unique ID from the XML. Before adding an object, you will have to manually check if an object with that ID already exists.

    UPDATE
    The key is to not add a managed object to the context until you have determined that it is new.
    This is pretty straightforward given the unique ID, but it sounds like you can’t parse for the unique ID first. In that case you should use a temporary mutable dictionary (NSMutableDictionary) to store the data as it’s parsed.
    If you determine that the friend is new, you can create it and copy the data over from the dictionary. If the friend is not new, you can discard the dictionary.

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

Sidebar

Related Questions

I need some advice about this... I have a program that serves as a
Need some advice about a best-approach for this problem: I've fallen madly in love
I need some advice/help on this, I can't see the wood from the trees
Afternoon all, In need of some technical advice from the masters... I know the
I need some advice regarding which database I should use. I want to create
I need some advice from experts :) I will develop a website using PHP
I need some advice in tackling a query. I can handle this in a
I need some advice on how to go about a particular issue I'm trying
Sorry if this is quite a long question, i need some advice on what
I've been thinking about this one for quite some time now, I need a

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.