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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:12:54+00:00 2026-05-11T20:12:54+00:00

I have an XML like this <resultGroups> <subGroups> <results> </results> <results> </results> </subGroups> <subGroups>

  • 0

I have an XML like this

<resultGroups> 
    <subGroups>
        <results> </results>
        <results> </results>
    </subGroups>
    <subGroups>
        <results> </results>
        <results> </results>
    </subGroups>    
    <name> </name>
</resultGroups>
<resultGroups> 
    <subGroups>
        <results> </results>
        <results> </results>
    </subGroups>
    <subGroups>
        <results> </results>
        <results> </results>
    </subGroups>    
    <name> </name>
</resultGroups>

I have this code to select number of results inside each resultGroup

$('resultGroups', $(xml)).each(function() {
    count = $('results', this).length;
    arr[i] = count;
    i++;
});

What I want is to get the name from each resultGroup tag and store it in an array.
How can I do that inside the above code?

How can I select only the name tag of the first resultGroup only without .each function?

  • 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-11T20:12:54+00:00Added an answer on May 11, 2026 at 8:12 pm

    If your XML looks like this:

    <resultGroups> 
        <subGroups>
            <results> </results>
        </subGroups>
        <subGroups>
            <results> </results>
        </subGroups>    
        <name>myname</name>
    </resultGroups>
    <resultGroups> 
        <subGroups>
            <results> </results>
            <results> </results>
        </subGroups>
        <subGroups>
            <results> </results>
            <results> </results>
        </subGroups>    
        <name>othername</name>
    </resultGroups>
    

    Using this code:

    var groups = {};
    $('resultGroups', $(xml)).each(function() {
        var count = $('results', this).length;
        var name = $('name',this).text();
        groups[name] = count;
    });
    

    After that, groups will be a dictionary (object, hence the {}) like so:

    {'myname': 2, 'othername': 4}
    

    Which you can access by doing groups.myname or groups['myname']

    To get only the name tags directly in resultGroups tag – I didn’t see any other in the example code, so I didn’t know there were more – use this code instead:

    var name = $(this).children('name').text();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have xml like this: <configurationData> <path name='b'> <path name='a'> <setting name='s1'> ![CDATA[XXXX]] </setting>
I have xml structure like this: <Group id=2 name=Third parentid=0 /> <Group id=6 name=Five
I have some xml like this: <Data> <Rows> <Row> <Field Name=title>Mr</Field> <Field Name=surname>Doe</Field> <Row>
I have XML that looks like this: <Parameter Name=parameter name Value=parameter value /> which
I have XML like this: <assessment name=Assessment> <section name=Section1> <item name=Item1-1/> <item name=Item1-2/> <item
I have XML like this: <exam> <section name=SampleSection1> <attributes> <variable_name data_type=String value=SCORE/> </attributes> <item
I have an XML like this <Authors> <Author name='Some Author'> <Book>B1</Book> <Book>B2</Book> <Book>B3</Book> </Author>
I have a XML like this: <group name=A> <element>1</element> <groups> <group name=B> <element>2</element> <element>3</element>
Suppose I have xml like this: <Products> <Product name=Liquid Oxygen> <Manufacturer name=Universal Exports country=UK
I have an xml like this <address> <street>abc</street> <number>123</number> </address> <address> <street>abc1</street> <number>345</number> </address>

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.