Parsing levels of XML in jquery -


here xml. going have many degrees, each degree have many schools, , each school have many specializations. page gave 3 dropdowns. not asking code preform onclicks nested dropdown updates. (unless has cool recurrence pattern work.

this problem having when ask degree degrees node , add text() dropdown text degree, school, spec... want dropdown "degree 1", "degree 1 school 1 spec...", sure idea, have tried adding "degrees.filter, , children" nothing.

i need handle on how parse xml nested nodes once level @ time.

thanks time.

<degrees>   <degree>   degree 1   <schools>     <school>school 1       <specializations>        <specialization>specialization 1</specialization>        <specialization>specialization 2</specialization>       </specializations>     </school>     <school>school 2       <specializations>        <specialization>specialization 3</specialization>        <specialization>specialization 4</specialization>       </specializations>     </school>   </schools>   </degree> </degrees> 

the current jquery

var degrees = $(pid).find('degrees');     degrees.find("degree").filter("degree").each(function () {     var select = $('#degree');     var value = $(this).text();     select.append("<option value='" + value + "'>" + value + "</option>");     }); 

the html

<select id="degree">     <option value="" selected="selected">-- select degree --</option> </select> 

here ended doing, allows me sort drop-down. please comment if has other ideas.

var degreelist = new array();                 $(xml).find('pid[id="' + pid + '"] degrees degree').each(function () {                     var item = new object();                     item.id = $(this).attr("id");                     item.value = $(xml).find('degrees degree[id=' + item.id + ']').text();                     degreelist.push(item);                 });                  degreelist.sort(function (a, b) {                     if (a.value.text > b.value.text) return 1;                     else if (a.value.text < b.value.text) return -1;                     else return 0                 })                  (var = 0; < degreelist.length; i++) {                     $('#degree').append("<option value='" + degreelist[i].id + "'>" + degreelist[i].value + "</option>");                 } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -