Chinaunix首页 | 论坛 | 博客
  • 博客访问: 925442
  • 博文数量: 264
  • 博客积分: 10107
  • 博客等级: 上将
  • 技术积分: 2455
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-09 16:34
文章分类

全部博文(264)

文章存档

2012年(1)

2011年(11)

2010年(128)

2009年(82)

2008年(42)

我的朋友

分类: 系统运维

2010-09-10 11:24:17

 
xml文件结构:books.xml
xml version="1.0" encoding="UTF-8"?>
<root>
    
<book id="1">
        
<name>深入浅出extjsname>
        
<author>张三author>
        
<price>88price>
    
book>
    
<book id="2">
        
<name>锋利的jQueryname>
        
<author>李四author>
        
<price>99price>
    
book>
    
<book id="3">
        
<name>深入浅出flexname>
        
<author>王五author>
        
<price>108price>
    
book>
    
<book id="4">
        
<name>java编程思想name>
        
<author>钱七author>
        
<price>128price>
    
book>
root>
页面代码:
DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jquery解析xmltitle>
<script type="text/javascript" src="js/jquery-1.4.2.min.js">script>
<script type="text/javascript">
    $(
function(){
        $.post('books.xml',
function(data){
            
//查找所有的book节点
            var s="";
            $(data).find('book').each(
function(i){
                
var id=$(this).attr('id');
                
var name=$(this).children('name').text();
                
var author=$(this).children('author').text();
                
var price=$(this).children('price').text();
                s
+=id+"    "+name+"    "+author+"    "+price+"
";
            }
);
            $('#mydiv').html(s);
        }
);
    }
);
script>
head>
<body>
    
<div id='mydiv'>div>
body>
html>
效果图:
 
完整示例下载
阅读(1231) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~