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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:09:52+00:00 2026-05-31T01:09:52+00:00

I am using NSXmlParser to extract a string from an XML file. The xml

  • 0

I am using NSXmlParser to extract a string from an XML file. The xml elements look like the following: <temp_f data="63"/>

I can successfully log the data from the xml tags but when I try to append a string to that data I receive an error saying: Attempt to mutate immutable object with appendString: The tempF is actually a mutable object, it’s declared as an NSMutableString *tempF; in the header file. I have successfully appended strings to NSMutableSrings before but for some reason it is not working in this case. What am I doing wrong, please help?

My code is:

if ([elementName isEqual:@"temp_f"]) {
        tempF = [[NSMutableString alloc] init];
        tempF = [attributeDict valueForKey:@"data"];
        [tempF appendString:@"°F"];
        NSLog(@"tempF: %@", tempF);
    }

Everything works fine without the appendString: method.

  • 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-31T01:09:53+00:00Added an answer on May 31, 2026 at 1:09 am

    Well, with

    tempF = [[NSMutableString alloc] init];
    

    you create a new mutable string and assign a pointer to the new object to the variable tempF, but with

    tempF = [attributeDict valueForKey:@"data"];
    

    directly below, you replace the pointer to the new mutable with a pointer to the string allocated by the XML parser to represent the attribute value — which is immutable as it seems. (Note, that you also introduce a memory leak). Try instead:

    tempF = [[NSMutableString alloc] init];
    [tempF appendString: [attributeDict valueForKey:@"data"]];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am extracting data from web service(xml file) using NSXmlParser.How can I write to
i am using NSXMLParser to parse xml data received from a web service in
I have the following xml file which I am parsing using NSXMLParser : <geometry
OK, I managed to read from an XML file using NSXMLParser , but now
I can parse an XML file using NSXMLParser . I can also get the
I'm processing a response from the server using NSXMLParser successfuly. Something like this <data>
I am parsing some XML from an RSS feed (using NSXMLParser) for a blog
Hello all I'm using NSXMLParser to parse some xml data. I'm using this data
I am currently using NSXMLParser mathods to parse my data something like this :
How do you extract attributes from XML using NSXML parser?? Heres my xml: <item>

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.