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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:40:14+00:00 2026-05-17T02:40:14+00:00

so here I am stuck at the simplest part (or so I thought) of

  • 0

so here I am stuck at the simplest part (or so I thought) of my small project for this morning. The goal was to build a simple XML Parser who takes every element they encounter and add it to a dictionary that will eventually hold all key/value pairs of the xml.

So an xml like this

<xml>
  <1stTag>text</1stTag>
  <2ndTag>some more text</2ndTag>
</xml>

Would end up in a dictionary with 2 key/value pairs:

{
1stTag:text;
2ndTag:some more text;
}

Adopting the NSXMLParser Framework I thought that I’d just store every encountered element and texts in variables self.elementInProgress and self.textInProgress (both NSStrings). Once the Element is finished I’d add the pair to the dictionary.

So here is the .h file:

    @interface MSParser : NSObject <NSXMLParserDelegate> 
    {
        NSString *elementInProgress;
        NSString *textInProgress;
        NSMutableDictionary *parsedXMLDict;
    }
@property (nonatomic, retain) NSString *textInProgress;
@property (nonatomic, retain) NSString *elementInProgress;
@property (nonatomic, retain) NSMutableDictionary *parsedXMLDict;

And the respective function in the implementation file:

@synthesize textInProgress, elementInProgress, parsedXMLDict;

- (void)parser:(NSXMLParser *)parser  didEndElement:(NSString *)elementName  namespaceURI:(NSString *)namespaceURI  qualifiedName:(NSString *)qName
{
    [self.parsedXMLDict setValue:self.textInProgress forKey:self.elementInProgress];
    NSLog(@"%@",[self.parsedXMLDict valueForKey:self.elementInProgress]);
}

Now, here I am, stumped that my NSLog returns Null! And I thought this was a no-brainer. What am I missing? Both self.textInProgress and self.elementInProgress are filled correctly according to the Debugger. I can trace it down to this line where I call setValue ForKey, which again is according to documentation and has worked more than once before for me. The dictionary just doesnt take the values. According to documentation, it would only act funny, if the passed setValue was nil, which here it isn’t… Any ideas?
It all looks good, not compiler errors or warnings, it just returns Null. Stumped, as I said…

  • 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-17T02:40:15+00:00Added an answer on May 17, 2026 at 2:40 am

    Somewhere in your code (probably in your init method) you need to be instantiating a NSMutableDictionary instance and assigning it to your property (or ivar, if you’re in your init method). Something like this:

    parsedXMLDict = [[NSMutableDictionary alloc] init];
    

    If you’re using a convenience construction that returns an autoreleased object, you’ll also need a retain.

    parsedXMLDict = [[NSMutableDictionary dictionaryWithCapacity:10] retain];
    

    In either case, make sure you have a corresponding release somewhere, probably in your dealloc.

    If you’re already doing the above, then perhaps you’ve already released parsedXMLDict earlier in your code? Look for places where you’re calling self.parsedXMLDict = nil that are getting called before your parser: didEndElement: ... method.

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

Sidebar

Related Questions

A little stuck here. I have a simple question I guess. Given the following
I am stuck here and i spend last 2 days resolving this issue but
i know this is basic but somehow i have been stuck here for some
I am stuck here. I have row in Postgres like this: id amount a
Ok guys im a bit stuck here. I usually use jquery to do this
I am stuck here. can not think of a clever way to do this.Need
I am stuck here. How can I clean this array: {data:[{id:5201521d42},{id:52049e2591},{id:52951699w4}]} So that it
I'm really stuck here. Im having an array looking like this below. And now
I can't believe I'm stuck here, but I can't seem to make a simple
I am stuck here and hope to get some guidance on this. I'm trying

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.