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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:48:19+00:00 2026-06-05T03:48:19+00:00

What I want to do: i) Parse XML data into a select option field

  • 0

What I want to do: i) Parse XML data into a select option field ii) when user makes a selection using the option box, many more form fields are then populated with relevant XML data based on the user selection.

I have this working with Adobe Spry (what is that I hear you cry!!!) – Currently, the user selects an option box which contains data from XML , for example “American Wigeon” which when selected then populates other form fields with the rest of the XML, such as “Turdus migratorius” and so on. If the user changes their mind and selects another, for example “American Robin”, the relevant XML for this bird will then populate the form fields.

I have found answers on here for getting parsed data into a select option, but cannot work out the next bit of using multiple fields.

My XML file looks like this (edited down to two entries, but approx 300 normally):

<?xml version="1.0" encoding="utf-8" ?>
<BIRD>

<Result>
<name>American Wigeon</name>
<latin>Anas americana</latin>
<rare>1</rare>
<id>68</id>
<breed>0</breed>
<winter>0</winter>
</Result>

<Result>
<name>American Robin</name>
<latin>Turdus migratorius</latin>
<rare>1</rare>
<id>255</id>
<breed>0</breed>
<winter>0</winter>

</BIRD>

I would like to get this to work in jQuery so I can start to add more functionality to the script.

Any help would really be appreciated.

Many thanks

Mark

EDIT up date:

I like the script written by Charlietfi and have tested this on jsFiddle (many thanks) – I am now having problems appending the additional XML data to form fields. As an example, if I select American Wigeon, I then want to put the additional XML data into FORM fields, that can then be submitted (so the value of “Rare” would go into a text field”)

I can get sample text into a form field BUT cannot get the selected additonal XML data in – CODE example below:

var xml = '<?xml version="1.0" encoding="utf-8" ?><BIRD><Result><name>American 
Wigeon</name><latin>Anas americana</latin><rare>1</rare><id>68</id><breed>0</breed>
<winter>0</winter></Result><Result><name>American Robin</name><latin>Turdus 
migratorius</latin><rare>1</rare><id>255</id><breed>0</breed><winter>0</winter>
</Result></BIRD>';

var $xml = $($.parseXML(xml));

$xml.find('Result').each(function() {
var data={}
$(this).children().each(function() {
    data[this.tagName]=$(this).text();
})
                                                                                              $('#test').data( data.id,  data).append('<option                                                                           value="'+data.id+'">'+data.name+'</option>');
  });


 $('#test').change(function(){
var data=$(this).data( $(this).val());   

var input = $( "#test2" ); // **this being the name of my text field**
 input.val( input.val() + "more text" );



    alert('ID:'+data.id +', Name:'+ data.name);    
  })

When the script runs, I select a bird from the option, this then brings up an alert box as expected PLUS inserted into the text field is “More text” (used this to make sure something gets added).

I am stuck on how to use” +data.id + ” and get that into #test2
Many thanks for every ones help and apologies if this is such a simple thing that I am missing.

  • 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-05T03:48:23+00:00Added an answer on June 5, 2026 at 3:48 am

    Following will dynamically parse the XML, creating both an option and a data object which will be stored on select element using jQuery data()

    var $xml = $($.parseXML(xml));
    
    $xml.find('Result').each(function() {
        var data={};
        /* loop over children of each "Result to create data object*/
        $(this).children().each(function() {
            data[this.tagName]=$(this).text();
        });
        /* add data to select and create option*/
        $('#test').data( data.id , data).append('<option value="'+data.id+'">'+data.name+'</option>');
    });
    
    /* change handler for select*/
    $('#test').change(function(){
        var data=$(this).data( $(this).val()); 
        /* here you would make updates to other fields */   
         alert('ID:'+data.id +', Name:'+ data.name);    
    })
    

    DEMO: http://jsfiddle.net/dpK7x/1/

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

Sidebar

Related Questions

I want to parse an XML file using SAX parser in java with this
i want to parse an xml like: <users> <user> <userName>mspeller</userName> <firstName>Mike</firstName> <lastName>Speller</lastName> <user> <userName>mspeller</userName>
I'm using XML::Simple to parse an XML file which I then want to use
I parse XML data and put it into an object. This takes fairly long
I have an XML file that I want to parse into a database in
I Want to Parse XML with Linq. Here is My XML Data. <?xml version=1.0
I want to parse xml files that have elements like these: <element>&amp</element> <element>&amp;</element> But
I want to parse XML in bash and xpath could do it. (To get
I want to parse a XML file. It throws the Exception while creating object:
I want to parse a XML document once - at Rails application startup. It

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.