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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:26:03+00:00 2026-05-26T11:26:03+00:00

I have 4 blocks of xml, that I want to parse whith jQuery making

  • 0

I have 4 blocks of xml, that I want to parse whith jQuery making one ajax call. Now four blocks of xml are different from each other(But the structure is same). I am trying to parse this xml by passing an id to each of the xml block, But in my ajax call I am not able to retreive the id attribute as it is the first thing that I need to capture to pass to the ajax function.

I tried something like this:

XML is here:

       <dropdown>
            <test id="1">
            <optionheading>
                <heads>Heading 1</heads>
                            <value>
                                    <values images='images/1.gif'>Option1</values>
                                    <values images='images/2.gif'>Option2</values>
                                    <values images='images/3.gif'>Option3</values>
                            </value>
            </optionheading>
    .....................................

    ............................
    </test>
    <test id='2">
    <optionheading>
                <heads id="b">H..................
    ..................
    ............
    </test>
</dropdown>

I need to get id of test1, test2, et-al

Ajax is Here:

$("document").ready(function() {
                $.ajax({ 
                    type: "GET",
                    url:"dropdown.xml",
                    dataType: "xml",
                    success :function(xml) {
                        var select = $("#mySelect"); 
                        //I am getting id here
                        var id=$(xml).find('test').attr('id'); 

                        $(xml).find('test'+id).each(function() {
                            $(this).find('optionheading').each(function() {
                            var opthead = $(this).fin......................
  • 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-26T11:26:04+00:00Added an answer on May 26, 2026 at 11:26 am

    If I’ve understood you well, the following should happen (output boldfaced):

    • <test id="IDHERE"> should populate <select ID="IDHERE">
    • <optionheading> should create an <optgroup> with a label as defined at <heads>
    • Each <optgroup> is populated with <option> elements, according to the given <values> elements

    The code below is the jQuery method to implement this idea, as requested.

    Note: $('test', xml) is a shorthand for $(xml).find('test').
    Note2: Since an ID must be unique, select#yourID is equal to #yourID.
    Note3: The <values> tag at the XML is not necessary for this script.

    success: function(xml){
        //Loop through each `<test>`
        $('test', xml).each(function(test_index){
            var id = $(this).attr('id'); //Get the ID of the `<test>`
            // Select <select> element with ID `ID` using the `select#ID` selector
            var select = $('select#' + id);
            $('optionheading', this).each(function() {
                $('values', this).each(function(){
                    var $values = $(this);
                    $('<option>')
                        .val($values.attr('images'))
                        .text($values.text())
                        .appendTo(optgroup);
                });
                $('<optgroup>')
                    .attr('label', $('heads', this).text())
                    .appendTo(select);
            });
        });
    }
    

    Possible HTML after executing:

    <select id='1'>
        <optgroup label='Heading 1'>
            <option value='images/1.gif'>Option1</option>
            <option value='images/2.gif'>Option2</option>
            <option value='images/3.gif'>Option3</option>
        <optgroup>
        ....
    </select>
    <select id="2">
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have blocks of content that are toggled on/off via jQuery and I want
I have a WCF service that is returning a block of xml. One element
I have XML in the following format which I want to reformat: <blocks> <!--
I have blocks of data that I want to write in a txt, or
I have an HTML/XML table generated by AJAX that displays limited columns of a
I have an XML file in the drawable-folder. I want parse the XML-file using
I have 3 blocks: one wrapper and 2 other inside the wrapper. Inside-blocks have
I have several blocks that look like this: <div class='templatechoicedesigncss'> <img src='/images/templatepics/random(100x140).png' /> <p>
I have a bunch of XML files, along with the DTD, that each have
I have a list of items that I want to be laid out horizontally.

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.