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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:27:37+00:00 2026-05-15T14:27:37+00:00

I’ve been working on importing XML into an iPad Core Data application. I have

  • 0

I’ve been working on importing XML into an iPad Core Data application. I have a working NSXMLParser implementation for my files, and have been able to import the simpler (ie attribute-only) elements into Core Data.

Some of the XML dated has nested elements with text, and I’m a bit stumped on how to get Core Data to play nicely in the callback-centric world of NSXML.

If I see a new XML element, I need to insert a new managed object into my context. If I do this in NSXML’s didStartElement:, I need to preserve a reference to it so that I can store my XML text element when didEndElement: is called.

Given that my XML elements are nested, I may have encountered several didStartElements: before I encounter a didEndElement:, so I need something more than a single object instance to preserve the managed object across callbacks. (Also, I think that insertNewObjectForEntityForName: is autoreleased, so I need to retain a copy of the managed object.)

I thought I might build an object stack out of NSMutableArray's addObject: and removeLastObject: methods, but I wonder if there’s something simpler, or I’ve missed some piece of the big picture here.

  • 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-15T14:27:37+00:00Added an answer on May 15, 2026 at 2:27 pm

    I’ve run unto a similar problem, and as you mentioned, ended up using stacks with addObject:, lastObject and removeLastObject:. It parses reasonably quickly.

    In my specific case, I had a number of Core Data entities, both with instance variables and to-many relationships to their child elements. I used two stacks, one for the objects, and one for the elements. In my case the parent elements did not have data of their own, ex:

    <Parent>
        <Parent_Data1>Foo</ParentData1>
        <Parent_Data2>Bar</ParentData2>
        <Child>
            <Child_Data1>Baz</Child_Data1>
        </Child>
    </Parent>
    

    So I had one stack of the entities that contained other entities (Parent and Child in my example), with another containing the keypaths corresponding to the data (Parent_Data1, Parent_Data2 and Child_Data1). When I found the data in parser:foundCharacters I would set it on the topmost entity using setValue:forKeyPath: and pop that when I got to parser:didEndElement:.

    Hope that helps.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.