zoukankan
html css js c++ java
jquery解析XML
xml文件结构:books.xml
<?
xml version="1.0" encoding="UTF-8"
?>
<
root
>
<
book
id
="1"
>
<
name
>
深入浅出extjs
</
name
>
<
author
>
张三
</
author
>
<
price
>
88
</
price
>
</
book
>
<
book
id
="2"
>
<
name
>
锋利的jQuery
</
name
>
<
author
>
李四
</
author
>
<
price
>
99
</
price
>
</
book
>
<
book
id
="3"
>
<
name
>
深入浅出flex
</
name
>
<
author
>
王五
</
author
>
<
price
>
108
</
price
>
</
book
>
<
book
id
="4"
>
<
name
>
java编程思想
</
name
>
<
author
>
钱七
</
author
>
<
price
>
128
</
price
>
</
book
>
</
root
>
页面代码:
<!
DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"
>
<
html
>
<
head
>
<
meta
http-equiv
="Content-Type"
content
="text/html; charset=UTF-8"
>
<
title
>
jquery解析xml
</
title
>
<
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
+
"
<br>
"
;
}
);
$('#mydiv').html(s);
}
);
}
);
</
script
>
</
head
>
<
body
>
<
div
id
='mydiv'
></
div
>
</
body
>
</
html
>
效果图:
转自:
http://www.blogjava.net/sxyx2008/archive/2010/07/10/325719.html
查看全文
相关阅读:
【项目管理】git和码云的使用
【Yii系列】处理请求
【Yii系列】Yii2.0基础框架
JDBC Java 程序从 MySQL 数据库中读取数据,并备份到 xml 文档中
Java 把一个文本文档的内容复制到另一个文本文档
Java 写一段字符到指定的文本文档中,如果该文本文档不存在,则创建该文本文档
Java 单字节、多字节读取文本文档中的内容
Java File mkdir() mkdirs()
JDBC Java 程序从 MySQL 数据库中读取数据,并封装到 Javabean 对象中
Java int类型与String类型互转
原文地址:https://www.cnblogs.com/zhangqs008/p/3618457.html
最新文章
python 面向对象五 获取对象信息 type isinstance getattr setattr hasattr
python 面向对象四 继承和多态
python 面向对象三 访问权限 下划线 双下划线
python 面向对象二 类和实例
python 面向对象一 OOP
Redis安装即python使用
mysql优化的常用方法
Django ContentType(ORM操作)
Vue环境搭建、创建与启动、案例
rest_framework五大模块
热门文章
JS 相关记录(scrollTo,JSON)
JS touch
JS 关于 bind ,call,apply 和arguments p8
git 对 Microsoft Word 进行版本控制
C语言实现粒子群算法(PSO)一
K均值聚类算法的MATLAB实现
C语言实现粒子群算法(PSO)二
遗传算法的C语言实现(一):以非线性函数求极值为例
遗传算法的C语言实现(二)
【Python系列】Python自动发邮件脚本
Copyright © 2011-2022 走看看