Skip to content

Instantly share code, notes, and snippets.

@z3bbster
Last active December 17, 2015 12:39
Show Gist options
  • Save z3bbster/5611443 to your computer and use it in GitHub Desktop.
Save z3bbster/5611443 to your computer and use it in GitHub Desktop.
//Load XML file
$(document).ready(function(){
$("#dvContent").append("<ul></ul>");
$.ajax({
type: "GET",
url: "BookList.xml",
dataType: "xml",
success: function(xml){
$(xml).find('Book').each(function(){
var sTitle = $(this).find('Title').text();
var sPublisher = $(this).find('Publisher').text();
$("<li></li>").html(sTitle + ", " + sPublisher).appendTo("#dvContent ul");
});
},
error: function() {
alert("An error occurred while processing XML file.");
}
});
});
//Code Ends
<?xml version="1.0" encoding="utf-8" ?>
<BookList>
<Book>
<Title>jQuery: Novice to Ninja</Title>
<Publisher>Site point</Publisher>
</Book>
<Book>
<Title>Learning jQuery</Title>
<Publisher>PACKT</Publisher>
</Book>
<Book>
<Title>Head First jQuery</Title>
<Publisher>O'Reilly</Publisher>
</Book>
<Book>
<Title>jQuery UI 1.8</Title>
<Publisher>PACKT</Publisher>
</Book>
</BookList>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment