Skip to content

Instantly share code, notes, and snippets.

@davidvanvickle
Created July 3, 2012 21:51
Show Gist options
  • Save davidvanvickle/3043573 to your computer and use it in GitHub Desktop.
Save davidvanvickle/3043573 to your computer and use it in GitHub Desktop.
jquery xml parse
Parse this (some.xml):
<root><xline a="1" b="2" /><xline a="3" b="4" /></root>
With this:
<div id="parsed">Loading...</div>
<script type="text/javascript" charset="utf-8">
$(document).ready(function () {
$.ajax({
type:'GET',
url:'some.xml',
dataType: 'xml',
success: function (x) {
$("#parsed").html('');
$(x).find('xline').each(function (i,itm) {
var h = $("#parsed").html();
var a = $(this).attr('a');
var b = $(this).attr('b');
h += '<p>a: '+a+', b: '+b+'</p>';
$("#parsed").html(h);
});
},
error:function() {
alert('Server error.');
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment