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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:54:45+00:00 2026-05-28T18:54:45+00:00

I am getting an XML format data from server and parsing it in an

  • 0

I am getting an XML format data from server and parsing it in an scenario. I am having problem putting this data in key, value pair using NSMutableDictionary. Because, NSMutableDictionary key is unique. So, it overwrites the key with the previous value existing if there are same keys are coming from xml.
For ex: My XML data is below.

<?xml version='1.0' encoding='utf-8'?><order>
            <number>123</number>
            <detail>

                <name>shoe</name> 
                <description>This is from nike</description>
                <price>10.00</price>

                <name>discount</name> 
                <description>This is from Arrow</description>
                <price>-1.00</price>

                <name>bag</name> 
                <description>This is a leather one</description>
                <price>10.00</price>

            </detail>
          </order>

[appDelegate.finalOrderDict setObject:trimmString forKey:elementName];

I am trying to put the data in key, value pair using NSMutableDictionary, because, i’ll be showing the output in another view like below.

Summary:
Shoe     $ 10.00
Discount $ -1.00   
Bag      & 10.00
Discount $ -2.00 

But, as the keys are repeating same, its overwriting the data from the existing one.

Could someone help me resolving duplicating of key in case if there are same keys present in the data and we try to put that in NSDictionary.

Thank you!

  • 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-28T18:54:46+00:00Added an answer on May 28, 2026 at 6:54 pm

    NSDictionary is behaving as intended – when -setObject:forKey: is called, an existing key-value pair is overwritten if the old key and the new key respond YES to -isEqual:. It sounds like you need to modify your data structure.

    One idea would be having appDelegate.finalOrderDict instead be an NSArray of NSDictionary objects. Each NSDictionary would then have “name” and “price” key-value pairs.

    You could also have each value promoted to an array if it already exists:

    id existingValue = [appDelegate.finalOrderDict objectForKey:forKey:elementName];
    if ([existingValue isKindOfClass:[NSMutableArray class]]) {
        [existingValue addObject:trimmString];
    } else if (existingValue) {
        [appDelegate.finalOrderDict setObject:[NSMutableArray arrayWithObjects:existingValue, trimmedString, nil] forKey:elementName];
    } else {
        [appDelegate.finalOrderDict setObject:trimmedString forKey:elementName];
    }
    

    This approach is riskier, however, as you have to type-check all objects obtained from finalOrderDict, to see if they are strings or arrays.

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

Sidebar

Related Questions

I'm stuck to getting data from this xml: <?xml version=1.0 encoding=UTF-8?> <document> <AAA>Header</AAA> <BBB>
I'm getting this XML from a service that I need to deal with. I'm
I'm having trouble getting JSON data from my Rails app to display on a
I am having URL of PHP file from where i am getting all data
Right now I'm getting schema in XML format like this <Header> <data1> </data1> <Line>
I'm getting XML like this: <Items> <Row attr1=val></Row> <Row attr1=val2></Row> </Items> This is valid
I'm looking for the best approach to getting an XML document from a JDBC
I've been having tons of problems getting the non-xml configuration for Castle Windsor set
The XML String I am getting from other application is converting & to &amp;
I'm having trouble getting a memory stream and a XML text writer class to

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.