日期:2014-05-16 浏览次数:20797 次
<?xml version="1.0" encoding="utf-8" ?>
<bookstore >
<book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
<title>The Confidence Man</title>
<author> Melville. Herman</author>
<price>11.99</price>
</book>
<book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
<title>The Gorgias</title>
<author> Plato. Sidas</author>
<price>9.99</price>
</book>
</bookstore>
<script src="http://www.coding123.net/js/jquery.js"></script>
<script>
$.ajax({
dataType: 'xml',
url: 'x.xml',
cache: false,
success: function (dom) {
var genre, publicationdate, ISBN, title, author, price;
$('book', dom).each(function () {
genre = this.getAttribute('genre');
publicationdate = this.getAttribute('publicationdate');
ISBN = this.getAttribute('ISBN');
title = $('title', this).text();
author = $('author', this).text();
price = $('price', this).text();
alert(genre + '\n' + publicationdate + '\n' + ISBN + '\n' + title + '\n' + author + '\n' + price);
});
},
error: function (xhr) { alert('xml路径有问题~\n' + xhr.responseText); }
});
</script>