日期:2014-05-16  浏览次数:20768 次

要求先解析该xml文档,并将得到的内容建立表格显示在html页面上
本帖最后由 showbo 于 2013-04-03 10:45:16 编辑
book.xml
<?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>

用DOM模型做
在线等,谢谢

------解决方案--------------------
javascript xml

楼主去了解怎么解析xml先把。。
------解决方案--------------------
<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>