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
查看全文
相关阅读:
网络编程
模块
内置函数
函数应用
万能参数
函数
爬虫
算法
Flask
linux
原文地址:https://www.cnblogs.com/zhangqs008/p/3618457.html
最新文章
Android中访问网络时url中带有特殊字符的问题
URL中的特殊字符处理
NavigationDrawer+listView 中actionBar的背景色设置
#游戏平台接入#Android游戏平台接入(一)#android客户端和C++底层的数据交互#jni编程#欢迎交流#
C++ Stack around the variable 'fn' was corrupted?该怎么处理
android中Logcat中颜色的意思
Android:R can not be resolved to be a variable
Python openpyxl【包】
Idea 配置 tomacat
Css 基础
热门文章
Java 基础(二)
Java 基础(一)
HTML 基础
JS ES6
WebStore 破解
Redis
前端
来试试
数据库
并发
Copyright © 2011-2022 走看看