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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:18:28+00:00 2026-05-26T07:18:28+00:00

Consider this XML Struture: <api> <status>200</status> <message>OK</message> <response> <item> <id>1</id> <image/> <title>Some title</title> <text/>

  • 0

Consider this XML Struture:

<api>
   <status>200</status>
   <message>OK</message>
   <response>
      <item>
         <id>1</id>
         <image/>
         <title>Some title</title>
         <text/>
         <email>some email</email>
         <channels>
            <item>
               <id>1</id>
               <group_id>1</group_id>
               <image>/path/to/image.png</image>
               <title>Some other title</title>
               <text/>
            </item>
            <item>
               <id>2</id>
               <group_id>1</group_id>
               <image>/path/to/image.png</image>
               <title>Some other title</title>
               <text/>
            </item>
      </item>
   </response>
</api>

There could be any number of items under response and any number of items under channels. Actually this structure is used for alot of different data but the generel layout looks like this (but i do not know the names of each xml element.

I have an XML parser (using TBXML parser) and it works great. I want to parse this structure into a combination of nsarrays and nsdictionaries..

Right now i got the following but iam not quite there yet! (and i cant seem to put the finger on what iam missing.

Objective-C code:

- (NSArray*) parsedResponse
{
    TBXML *xml = [[TBXML alloc] initWithXMLData:self.responseData];
    TBXMLElement *rootXML = xml.rootXMLElement;

    NSArray *_data;

    if(rootXML != nil)
    {
        TBXMLElement *xml = [TBXML childElementNamed:@"status" parentElement:rootXML];
        if(xml != nil)
            _data = [NSArray arrayWithObject:[self traverseElement:xml]];
    }

    return [_data autorelease];
}

- (NSMutableDictionary*) traverseElement:(TBXMLElement*)_element
{
    NSMutableDictionary *_items = [[NSMutableDictionary alloc] init];

    if(_element != nil)
    {
        int i = 0;
        do {
            if(_element == nil)
                continue;

                    // If there is a firstChild, there is subelements
            if(_element->firstChild)
            {
                             //need to do some magic here? i can't figure it out.. 
                NSArray *_item = [NSArray arrayWithObject:[self traverseElement:_element->firstChild]];
                NSString *key = [NSString stringWithFormat:@"%@%d", [TBXML elementName:_element], i];

                [_items setValue:_item forKey:[TBXML elementName:_element]];

            }
            else
                [_items setValue:[TBXML textForElement:_element] forKey:[TBXML elementName:_element]];

            i++;

        } while ((_element = _element->nextSibling));
    }

    return [_items autorelease];
}

Any suggestions?

  • 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-26T07:18:29+00:00Added an answer on May 26, 2026 at 7:18 am

    use NSXMLParser and its delegate methods.

      parser:didStartElement:namespaceURI:qualifiedName:attributes:
    
      parser:foundCharacters:
    
      parser:didEndElement:namespaceURI:qualifiedName:
    

    You should refer XML Parsing Guide.

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

Sidebar

Related Questions

Consider this example from w3schools : <?xml version=1.0 encoding=ISO-8859-1?> <bookstore> <book category=COOKING> <title lang=en>Everyday
Consider the following XML: <response> <status_code>200</status_code> <status_txt>OK</status_txt> <data> <url>http://bit.ly/b47LVi</url> <hash>b47LVi</hash> <global_hash>9EJa3m</global_hash> <long_url>http://www.tumblr.com/docs/en/api#api_write</long_url> <new_hash>0</new_hash> </data>
Consider this simple XML document. The serialized XML shown here is the result of
Consider this scenario: I've an XML file called person.xml with the following data in
consider this: I'm inside a (selfbuilt) XML Editor and am about to add a
Consider the following XML: <?xml version=1.0 encoding=ISO-8859-1?> <catalog> <cd> <title>Empire Burlesque</title> <artist> <name>Bob</name> <surname>Dylan</surname>
I have the following XML document: <x> <a>Some text</c> <b>Some text 2</b> <c>Some text
Consider simple XML document: <html><body> <table> <tr><td> Item 1</td></tr> <tr><td> Item 2</td></tr> </table> </body></html>
Consider this XML file. Note the first Tutorial has an Author child element, and
Consider this simple xml element example: <parent foo=1 bar=2 foobar=3> <child/> </parent> In the

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.