首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

要求先解析该xml文档,并将失去的内容建立表格显示在html页面上

2013-04-20 
要求先解析该xml文档,并将得到的内容建立表格显示在html页面上本帖最后由 showbo 于 2013-04-03 10:45:16

要求先解析该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>

热点排行