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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:21:07+00:00 2026-05-16T22:21:07+00:00

I am trying to parse an XML to extract values of certain variables. Here’s

  • 0

I am trying to parse an XML to extract values of certain variables. Here’s an example:

<?xml version='1.0'?>
  <Main xmlns='http://www.abc.uk' version='1.0' name='full'>
    <child1 version='2.0'>
    <value1> xyz </value1>
    <userinfo>
       <name> joe </name>
       <pass> joepass </pass>
   </userinfo>
    </child1>
</Root>

Question:
How do I extract the ‘xyz’ value to display ?
How do I extract ‘joe’ and ‘joepass’ to display ?

From my understanding, child1 is the root with attribute ‘version’. ‘value1’ and ‘userinfo’ are both elements. In Cocoa, how would I display these values ? I can do a [child elementsForName:@”userinfo” and it displays all the values. I need to specifically extract ‘joe’ and ‘joepass’. 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-16T22:21:07+00:00Added an answer on May 16, 2026 at 10:21 pm

    How do I extract the ‘xyz’ value to
    display ? How do I extract ‘joe’ and
    ‘joepass’ to display ?

    With something like this. This assumes you have your XML in an NSString:

    NSXMLDocument* xmlDoc;
    NSError* error = nil;
    NSUInteger options = NSXMLNodePreserveWhitespace|NSXMLDocumentTidyXML;
    xmlDoc = [[NSXMLDocument alloc] initWithXMLString:xmlString
                                              options:options
                                                error:&error];
    if (!error)
    {
        NSArray* value1Nodes = [xmlDoc nodesForXPath:@".//Main/value1" error:&error];
        if (!error)
        {
            NSXMLNode* value1node = [value1Nodes objectAtIndex:0];
            NSString* value1 = [value1node stringValue];
            // .. do something with value1
        }
    
        NSArray* userInfoNodes = [xmlDoc nodesForXPath:@".//Main/userinfo" error:&error];
        if (!error)
        {
            for (NSXMLNode* userInfoNode in userInfoNodes)
            {
                NSXMLNode* nameNode = [[userInfoNode nodesForXPath:@"./name" error:&error] objectAtIndex:0];
                NSXMLNode* passNode = [[userInfoNode nodesForXPath:@"./pass" error:&error] objectAtIndex:0];
                NSString* name = [nameNode stringValue];
                NSString* pass = [passNode stringValue];
                // .. do something with name and pass
        }
    }
    

    See more details in Apple’s Tree-Based XML Programming Guide.

    From my understanding, child1 is the
    root with attribute ‘version’.
    ‘value1’ and ‘userinfo’ are both
    elements.

    Main is the root node in this XML document, not child1.

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

Sidebar

Related Questions

I am trying to parse JSON in an Adobe Flex app, using http://www.mikechambers.com/blog/2006/03/28/tutorial-using-json-with-flex-2-and-actionscript-3/'>This Tutorial
I'm trying to parse a html page and extract 2 values from a table
I'm new to xml. I'm trying to parse an xml file to extract data
I have been trying to parse this xml in c# <schema uri=http://blah.com/schema > <itemGroups>
Since Days i'm trying to parse a YOUTUBE-XML-Feed by using GDATA-API for iOS. http://code.google.com/intl/de-DE/apis/youtube/2.0/developers_guide_protocol_channel_search.html
I'm trying to parse objects to XML in Delphi, so I read about calling
I'm trying to use XPath to parse an XML document. One of my NSXMLElement's
I'm trying to parse an Atom feed programmatically. I have the atom XML downloaded
I am trying to parse following SOAP response coming from Savon SOAP api <?xml
I am trying to parse an XML response from a website in C#. 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.