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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:40:20+00:00 2026-05-25T09:40:20+00:00

I have the following very simple XML returned from a webserver which I use

  • 0

I have the following very simple XML returned from a webserver which I use ASIHttpRequest to connect to:

<element1>something</element1>
<element2>somethingelse</element2>
<element3>anotherthing</element3>

ASIHttpRequest can return it as NSData or NSString. I need to parse the information, what is the easiest way to do so?

Thanks

  • 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-25T09:40:20+00:00Added an answer on May 25, 2026 at 9:40 am

    There are some XML parsers available for iOS NSXMLParser, libxml2 (DOM and SAX),TBXML,KissXML. You can refer http://www.raywenderlich.com/553/how-to-chose-the-best-xml-parser-for-your-iphone-project to choose best XML Parser (Speed and memory footprint). Easiest would be TBXML. NSXMLParser is easy as well.

    NSXMLParser* xmlParser = [[NSXMLParser alloc] initWithData:receivedXMLData];//init NSXMLParser with receivedXMLData
    [xmlParser setDelegate:self]; // Set delegate for NSXMLParser
    [xmlParser parse]; //Start parsing
    [xmlParser release];
    
    //Delegate Methods
    //Have a instance variable NSMutableString* currentString; to hold data between elements and NSMutableArray* elementsArray; to hold parsed data
    
    - (void)parserDidStartDocument:(NSXMLParser *)parser
    {
        elementsArray = [[NSMutableArray alloc] init];
    }
    
    //store all found characters between elements in currentString mutable string
    - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
    {
        if(!currentString)
        {
            currentString = [[NSMutableString alloc] init];
        }
        [currentString appendString:string];    
    }
    
    //When end of XML tag is found this method gets notified
    - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
    {
        if([elementName isEqualToString:@"element1"])
        {
            [elementsArray addObject:currentString];
            [currentString release],currentString=nil;
            return;
        }
        if([elementName isEqualToString:@"element2"])
        {
            [elementsArray addObject:currentString];
            [currentString release],currentString=nil;
            return;
        }
        if([elementName isEqualToString:@"element3"])
        {
            [elementsArray addObject:currentString];
            [currentString release],currentString=nil;
            return;
        }
        [currentString release],currentString =nil;
    }
    
    //Parsing has ended
    - (void)parserDidEndDocument:(NSXMLParser *)parser
    {
        NSLog(@"Content of Elements Array: %@",elementsArray);
            [elementsArray release],elementsArray=nil;
    }
    
    - (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError
    {
        UIAlertView* parseErrorAlert = [[UIAlertView alloc] initWithTitle:@"Parse Error" message:[NString stringWithFormat:"%@",[parseError localizedDescription]] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [parseErrorAlert show];
        [parseErrorAlert release];
    }
    

    You have other delegate methods too like parseErrorOccured. Refer http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html

    For TBXML : http://tbxml.co.uk/TBXML/API.html
    Updated: Implemented parseError delegate method and valid xml example
    XML You posted in code is not a valid XML (You can check XML validation online: http://validator.w3.org/#validate_by_input) so it will throw an parseError. Here is valid XML for XML you posted in question:

    <?xml version="1.0"?>
    <root>
     <element1>something</element1>
     <element2>somethingelse</element2>
     <element3>anotherthing</element3>
    </root>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following very simple XML file and I want to quickly parse
I have following, very simple, XML config for PHPUnit: <phpunit bootstrap=/_tests/TestAutoload.php> <testsuites> <testsuite name=Unit
I have the following very simple Javascript-compatible regular expression: <script type=text/javascript id=(.+) src=([^]+)> I
I have got the following very simple code: function init() { var articleTabs =
I have the following PHP code doing a very simple select into a table.
I have a very simple Java RMI Server that looks like the following: import
I have the following function which works very well within a $(document).ready(function(){ $('.threadWrapper >
It might be very simple but I think I am missing something. I have
I'm a beginner at XSL FO. I have a very simple XML document :
I have a very simple application which currently has a single Linq to Sql

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.