What kind of sorting? xml = '<base>'; xml += '<item type="c">one</item>'; xml += '<item type="b">two</item>'; xml += '<item type="d">three</item>'; xml += '<item type="f">three</item>'; xml += '<item type="a">three</item>'; xml += '</base>';
var sorted = $(xml).filter('item').get().sort(function(a,b){ var at = $(a).attr('type'), bt = $(b).attr('type'); return (at < bt) ? -1 : 1; }); $(sorted).each(function(){ console.log( this ); }); https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Global_Objects/Array/Sort - ricardo On Jan 21, 10:01 pm, skube <sku...@gmail.com> wrote: > It seems jQuery is really great at traversing an XML object. It is > quite easy to gather and filter node data. However I can't seem to > find any information regarding sorting XML using jQuery. Is it > possible? Or is there a plug-in? > > I have a project which requires me to read an XML file, then filter > and sort the data. Filtering I can do, but I have no idea how to sort > XML. Since arrays are easily sortable in JS, my idea is to convert the > XML into an array first, then filter the array (which is not as easy > as filtering XML w/ jQuery) then sort the array. > > Does anyone have any better ideas? > > thanks, > skube