<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<style>
h2 {color: #555; }
.p1 {color: #f99; }
.p2 {color: #9f9; }
.p3 {color: #99f; } </style>
<ul id="ul">
<li>
<p class="p4"></p>
<h2></h2>
<p class="p1"></p>
<p class="p2"></p>
<p class="p3"></p>
</li>
</ul>
</body>
</html>
<script>
window.onload = function() {
var xhr = null;
if(window.XMLHttpRequest){
xhr = new XMLHttpRequest();
}else{
xhr = new ActiveXObject('Microsoft.XMLHTTP');
} var url = 'xml/1.xml?';
var para = '?_t='+new Date().getTime();//传递到send()当中去,不会有缓存 // xhr.setRequestHeader('Content-Type','application/x-form-www-urlencoded')
// Failed to execute 'setRequestHeader' on 'XMLHttpRequest': The object's state must be OPENED. xhr.open('post',url,true);//url中不再包含参数
xhr.setRequestHeader('Content-Type','application/x-form-www-urlencoded')//必须位于open之后,send之前
xhr.send(para);
xhr.onreadystatechange = function () {
if(xhr.readyState == 4 && xhr.status == 200 ) {
//得到的XML是一个对象,这个对象有各种属性和方法
var data = xhr.responseXML;
var NOVEL = data.getElementsByTagName('NOVEL')[0];
var books = NOVEL.getElementsByTagName('book');
var len = books.length;
//console.log(NOVEL);
var str = '';
for(var i=0;i<len;i++) {
str+= '<li><h2>'+getNodeText(books[i].getElementsByTagName('name')[0])+'</h2>';
str+= '<p class="p4">'+getNodeText(books[i].getElementsByTagName('author')[0])+'</p>';
str+= '<p class="p2">'+getNodeText(books[i].getElementsByTagName('publish_time')[0])+'</p>';
str+= '<p class="p3">'+getNodeText(books[i].getElementsByTagName('publish_time')[0])+'</p>';
str+= '<p class="p1">'+getNodeText(books[i].getElementsByTagName('publish_time')[0])+'</p></li>';
}
document.getElementById('ul').innerHTML = str;
}
} function getNodeText(node){
if(window.ActiveXObject){//IE
return node.text;
}else{//标准浏览器
if(node.nodeType == 1){
return node.textContent;
}
}
} }
</script>
<?xml version="1.0" encoding="utf-8"?>
<bookstore>
<NOVEL>
<book>
<name>Herry Porter</name>
<author>J.K Rolling</author>
<publish_time>2058</publish_time>
</book>
<book>
<name>三国演义</name>
<author>罗贯中</author>
<publish_time>1984</publish_time>
</book>
<book>
<name>水浒传</name>
<author>施耐庵</author>
<publish_time>2501</publish_time>
</book>
<book>
<name>红楼梦</name>
<author>高雪琴</author>
<publish_time>1865</publish_time>
</book>
</NOVEL>
<MATH>
<book>
<name>圆周率</name>
<author>猪无能</author>
<publish_time>1869</publish_time>
</book>
<book>
<name>勾股定理</name>
<author>沙悟净</author>
<publish_time>1875</publish_time>
</book>
<book>
<name>相对论</name>
<author>唐玄奘</author>
<publish_time>1886</publish_time>
</book>
</MATH>
</bookstore>

  

最新文章

  1. 关于setInterval()你所不知道的地方
  2. hashMap 深入理解
  3. 关于防止App被第三方应用Kill掉的问题
  4. MVC模式下如何实现RegisterStartupScript等功能
  5. 初识Windows窗体(包括各种控件,属性,方法)
  6. 【转】【WPF】WPF 自定义快捷键命令(Command)
  7. Apache Thrift
  8. Hide/Show running Console
  9. EntityFramework 和 linq 判断是否在指定时间段内的方法
  10. SASS组件开发
  11. 网页制作之JavaScript部分3--事件及事件传输方式(函数调用 练习题 )重要---持续更新中
  12. bzoj1355——2016——3——15
  13. rsync安装及其配置
  14. 基于Python的数据分析(1):配置安装环境
  15. java网页爬数据获取class中的空格
  16. [LeetCode] Random Point in Non-overlapping Rectangles 非重叠矩形中的随机点
  17. MSIL 教程
  18. 获取CPU序列号、网卡MAC地址、硬盘序列号
  19. Java中BigDecimal类介绍及用法
  20. 矩阵快速幂(以HDU1757为例)

热门文章

  1. GCP消息队列Pubsub详解,简单好用还不用自己运维
  2. Unity 异步加载 进度条
  3. Jenkins+SonarQube实现C#代码质量检查
  4. 42、sort命令
  5. 面试官:spring中定义bean的方法有哪些?我一口气说出了12种,把面试官整懵了。
  6. layui 点击按钮 界面会刷新问题
  7. JavaWeb入门知识梳理
  8. Java核心基础第1篇-走进Java世界
  9. imply套件以及plyql的安装
  10. Centos中安装Node.Js