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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:41:00+00:00 2026-05-21T06:41:00+00:00

I have the following xml: <?xml version=1.0 encoding=UTF-8?> <Message> <Text>Town park travel</Text> <Theme>Ready for

  • 0

I have the following xml:

<?xml version="1.0" encoding="UTF-8"?>
<Message>
    <Text>Town park travel</Text>
    <Theme>Ready for racing?</Theme>
    <Activate_date>2011-03-08</Activate_date>
    <Login>Simon</Login>
    <Name>Simon </Name>
    <Longitude>46.00339</Longitude>
    <Latitude>51.515381</Latitude>
</Message>

How can I get elements To NSMutableDictionary?

i tried

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{            
if ([elementName isEqualToString:@"Message"]){
    listOfFriends = [[NSMutableDictionary alloc] init];
    if ([elementName isEqualToString:@"text"]) {
        [listOfFriends setObject: elementName forKey @"text" ];
    }
    }

But it is wrong

Now i use same code:

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{            
if ([elementName isEqualToString:@"Message"]){
    listOfFriends = [[NSMutableDictionary alloc] init];
} else if ([elementName isEqualToString:@"Text"] || [elementName isEqualToString:@"Theme"] || [elementName isEqualToString:@"Activate_date"] || [elementName isEqualToString:@"Login"] || [elementName isEqualToString:@"Longitude"] || [elementName isEqualToString:@"Latitude"]) {
    [currentElement setString:@""];
    storingCharacters = YES;
}
}   

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:@"Message"]) {
    [listOfFriends release];
} else if ([elementName isEqualToString:@"Text"]) {
    txt.text = currentElement;
} else if ([elementName isEqualToString:@"Theme"]) {
    theme.text = currentElement;
} else if ([elementName isEqualToString:@"Activate_date"]) {
    aDate.text = currentElement;
} else if ([elementName isEqualToString:@"Login"]) {
    autor.text = currentElement;
} 
storingCharacters = NO;
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if (storingCharacters) [currentElement appendString:string];
}

But i have empty Lables on view…

  • 1 1 Answer
  • 1 View
  • 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-21T06:41:01+00:00Added an answer on May 21, 2026 at 6:41 am

    NSXMLParser is stream-based, and sends various messages to its delegate when it encounters particular components in the XML stream – an opening tag, text, an end tag, and so forth. So, create an instance of NSXMLParser, and assign to it a delegate that you write that conforms to the NSXMLParserDelegate protocol. (Edit: From the code you added to your question, it looks like you may have already done this part, or at least made a good start on it.)

    In your delegate class’ -parser:didStartElement:... method, check the element name. If it’s “Message”, create a new NSMutableDictionary to hold the information in its child elements, and store that in a property: (Edit: In your code, it looks like you’ve declared the instance variable, but you should use dot-syntax to access it as a property, to make sure the correct memory-management happens.)

    self.listOfFriends = [NSMutableDictionary dictionary];
    

    For other element names, create an empty NSMutableString that will be used to hold text, and store that in a property:

    self.thisString = [NSMutableString string];
    

    In your -parser:foundCharacters: method, append the string to the mutable string property you created earlier.

    [self.thisString appendString:string];
    

    Finally, in your -parser:didEndElement:... method, check the element name. If it’s “Message,” you’re done with this message element. If your XML stream has only one Message element (as in the example), you can now print the dictionary you’ve built, or whatever else it is you wanted to do with it. If there can be multiple Message elements, you could add the just-completed one to an array.

    If the just-ended element is not a Message, add it to the dictionary with -setValue:forKey: passing the element name as a key, and the built-up string you created while receiving earlier -parser:foundCharacters: messages as the value.

    [self.listOfFriends setValue:self.thisString forKey:elementName];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question. My input XML looks like <?xml version=1.0 encoding=UTF-8?> <Text> <Message>this
I have the following simplified XML: <?xml version="1.0" encoding="UTF-8" ?> <MATMAS05> <IDOC BEGIN="1"> <E1MARAM
I have the following simplified XML structure: <?xml version="1.0" encoding="UTF-8" ?> <INVOIC02> <IDOC BEGIN="1">
I have the following string loaded to an XML document: <?xml version='1.0' encoding='utf-8'?> <soapenv:Envelope
I have a WebService with following wsdl file: <?xml version='1.0' encoding='UTF-8'?><wsdl:definitions name=BBAppWebAccessService targetNamespace=com.test xmlns:ns1=http://schemas.xmlsoap.org/soap/http
I have the following file Log4net.config in my bin directory: <?xml version=1.0 encoding=utf-8 ?>
I have the following simplified XML structure: <?xml version="1.0" encoding="UTF-8"?> <ExportData> <TransportHeader> <Timestamp>2011-01-16 06:00:33</Timestamp>
I have the following Xml in my Resources.xmltest: <?xml version=1.0 encoding=utf-8 ?> <Response xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
I have the following Ant build file: <?xml version=1.0 encoding=UTF-8?> <project default=build name=MyAntScript> <!--
Say I have this following XML structure: <?xml version=1.0 encoding=UTF-8?> <main> <parent> <child1>some value</child1>

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.