jQuery parse xml and keep order



I have an xml with mixed node content, I want to parse the xml and extract information based on the order that they appear in.


For example :



<booklist>
<hardcover>
<title>some title </title>
</hardcover>
<paperback>
<title>some title </title>
</paperback>
<paperback>
<title>some title </title>
</paperback>
<hardcover>
<title>some title </title>
</hardcover>
<paperback>
<title>some title </title>
</paperback>
<paperback>
<title>some title </title>
</paperback>
<hardcover>
<title>some title </title>
</hardcover>
</booklist>




I initially extracted each type using $.find() then concatenated the list back together, but the order is lost.



jQuery(xml).find('hardcover').each(function(){
...
hardcoverlist.push(hardcoverobj);

..});


jQuery(xml).find('paperback').each(function(){
paperbacklist.push(paperbackobj);
..});


Is there a way to tell find() to look for either/or ? like so jQuery(xml).find('paperback || hardcover')


No comments:

Post a Comment