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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:38:49+00:00 2026-06-13T06:38:49+00:00

This is the XML File: <Test> <Category> <SubCat> <Name>Name</Name> <Properties> <Key>Key</Key> <Value>Value</Value> </Properties> </SubCat>

  • 0

This is the XML File:

<Test>
    <Category>
        <SubCat>
            <Name>Name</Name>
            <Properties>
                <Key>Key</Key>
                <Value>Value</Value>
            </Properties>
        </SubCat>
        <SubCat>
            <Name>Name</Name>
            <SubCat>
                <Name>AnotherName</Name>
                <Properties>
                    <Key>Key</Key>
                    <Value>Value</Value>
                </Properties>
            </SubCat>
        </SubCat>
    </Category>
</Test>

I would like to get the Name. But only the Name of the first SubCat.
And the properties key value. The problem is the SubCat exist two times.

I tried this:

$(xml).find('SubCat').each(function() {
    var name = $(this).find("Name").text();
    alert(name);

}

but this show the name of the first and the second SubCat.

i search for something like this.

rootElement(Category).selectallchildren(SubCat).Name for the first SubCat Name
rootElement(Category).selectallchildren(SubCat).(SubCat).Name for the second SubCat Name

And same explicit select for the Key and values

  • 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-06-13T06:38:50+00:00Added an answer on June 13, 2026 at 6:38 am

    The trick here is to make use of jQuery’s ability to evaluate CSS3 selectors.

    SubCat:nth-of-type(1) selects every first occurrence of SubCat with arbitrary parent elements.

    So this should work:

    $(xml).find("SubCat:nth-of-type(1)").each(function(){
        var name = $(this).find("Name").text(),
            property = { };    //use an object to store the key value tuple
        property[$(this).find("Properties Key").text()] = $(this).find("Properties Value").text();
    
        console.log(name, property);
    });
    
    //Output:
    //Name Object { Key="Value" }
    //AnotherName Object { Key="Value"}
    

    Hopefully that’s what you want; when writing my first answer I obviously misinterpreted your question, sorry for the confusion…

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

Sidebar

Related Questions

This is an example XML file that would come from the Android Client. <test>
I am receiving this XML file which I would like to validate. Ideally I
I have this xml file: <test time=11.11.2011 11:11 > <field type=one value=10/> <field type=two
I have this xml-file: <objects> <object> <value>test</value> </object> <object> <value>foo</value> </object> <object> <value>bar</value> </object>
Trying to parse out this xml file to get a list of Elements but
Imagine this XML file (sorry for sick example!!) <DOC> <Test> <Name>1 vs 100 Pre
I've got test xml file that looks like this: <Person> <ContactInfo> ... <ContactInfo> </Person>
I have an xml file <?xml version=1.0?> <category> <name>SWEATERS</name> <name>WATCHES</name> <name>PANTS</name> <name>test</name> <name>1</name> </category>
I have this test code that just saves an XML file to a folder.
I have this inside my spring xml file: <object type=Test.Web.Utilities.TestClass, Test.Web singleton=false id=TestClass> <property

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.