自动检索XML数据
来源:互联网 发布:java环境变量配置win7 编辑:程序博客网 时间:2024/05/17 22:19
1.books.html
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script>
var xmlHttpReq = false;
function createXMLHttpRequest(){
try{
//Firefox,Opera8.0+,Safari
xmlHttpReq = new XMLHttpRequest();
}catch(e){
//Internet Explorer
try{
//Internet Explorer 6.0
xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
//Internet Explorer 5.5
xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
alert("/u4f60的浏览器不支持AJAX!");
return false;
}
}
}
}
function send(url,responseMethod){
createXMLHttpRequest();
xmlHttpReq.open("GET",url,true);
xmlHttpReq.onreadystatechange=responseMethod;//指定响应的函数
xmlHttpReq.send(null);//发送请求
}
//------------------------
function search(){
send('/AjaxApplication/books.xml',parse);
}
function parse(){
if(xmlHttpReq.readyState==4){//对象状态
if(xmlHttpReq.status==200){//信息已经成功返回,开始处理信息
var xmlStr = xmlHttpReq.responseText;
xmlStr = parseXML(xmlStr);
//输出结果
document.getElementById("txtHint").innerHTML=xmlStr;
}else{
alert("/u6240请求的页面有异常");
}
}
}
function parseXML(xmlStr){
var key = document.getElementById("key").value.toString();
//创建DOM对象
var xmlDoc = null;
if(window.ActiveXObject){//IE
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
}else if(document.implementation&&document.implementation.createDocument){//Mozilla,Firefox,opera
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.load(xmlStr);
var str = "";
xmlDoc.onload = function getMes(){
var tableStr = "";
if(xmlDoc!=null){
tableStr+="<table border='1'>";
var x = xmlDoc.getElementsByTagName("book");
for(i=0;i<x.length;i++){
var name = x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue;
var price = x[i].getElementsByTagName("price")[0].childNodes[0].nodeValue;
var author = x[i].getElementsByTagName("author")[0].childNodes[0].nodeValue;
var year = x[i].getElementsByTagName("year")[0].childNodes[0].nodeValue;
if(name.indexOf(key)==-1){
continue;
}else{
tableStr+= "<tr>";
tableStr+= "<td>"+name+"</td>";
tableStr+= "<td>"+price+"</td>";
tableStr+= "<td>"+author+"</td>";
tableStr+= "<td>"+year+"</td>";
tableStr+= "</tr>";
}
}
tableStr+="</table>";
alert(tableStr);
}
str = tableStr;
}
return str;
}else{
alert("/u6d4f览器不能处理!");
}
var tableStr = "";
if(xmlDoc!=null){
xmlDoc.async = false;
xmlDoc.loadXML(xmlStr);
tableStr+="<table border='1'>";
var x = xmlDoc.getElementsByTagName("book");
for(i=0;i<x.length;i++){
var name = x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue;
var price = x[i].getElementsByTagName("price")[0].childNodes[0].nodeValue;
var author = x[i].getElementsByTagName("author")[0].childNodes[0].nodeValue;
var year = x[i].getElementsByTagName("year")[0].childNodes[0].nodeValue;
if(name.indexOf(key)==-1){
continue;
}else{
tableStr+= "<tr>";
tableStr+= "<td>"+name+"</td>";
tableStr+= "<td>"+price+"</td>";
tableStr+= "<td>"+author+"</td>";
tableStr+= "<td>"+year+"</td>";
tableStr+= "</tr>";
}
}
tableStr+="</table>";
}
return tableStr;
}
</script>
</head>
<body>
输入关键字:<input type="text" id="key" onkeyup="search()">
图书信息:<span id="txtHint"></span>
</body>
</html>
2.books.xml
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book isbn="001">
<name>《水浒传》</name>
<price>80</price>
<author>施耐庵</author>
<year>元末</year>
</book>
<book isbn="002">
<name>《西游记》</name>
<price>90</price>
<author>吴承恩</author>
<year>明代</year>
</book>
<book isbn="003">
<name>《三国演义》</name>
<price>75</price>
<author>罗贯中</author>
<year>元末</year>3
</book>
<book isbn="004">
<name>《红楼梦》</name>
<price>75</price>
<author>曹雪芹</author>
<year>清代</year>
</book>
</books>
- 自动检索XML数据
- xml用于非结构数据检索技术
- dw子数据窗口dddw自动检索数据
- 数据检索--区域检索
- Android 之EditText自动检索Listview中的数据
- Hibernate数据检索策略和.hbm.xml映射文件
- 设置下拉数据窗口不自动检索以提高检索和插入速度
- 数据检索
- 数据检索
- 检索数据
- 导出数据到xml(自动下载)
- 自动检索用户名重复性
- hbm.xml检索策略
- 检索xml节点
- 请问如何在检索数据同时自动生成一个序号字段
- 全文检索、数据挖掘、推荐引擎系列6---基于KMean的文本自动算法
- 全文检索、数据挖掘、推荐引擎系列6---基于KMean的文本自动算法
- 全文检索、数据挖掘、推荐引擎系列6---基于KMean的文本自动算法
- Qt Embedded 4.5.3 的移植和触摸屏校正
- ThreadLocal的几种误区
- 工作分享
- 使用KDevelop 怎么就那么难
- 人的一生,到底在追求什么?
- 自动检索XML数据
- 今天第二步,相差很久啊
- ReportingServices无法在SharePoint集成模式下发布报表:http 400错误
- 154
- Windows7下的Intel 82852/82855 GM/GME Graphics Controller驱动安装笔记
- 一个简单的C#多线程间同步的例子【转】
- 加入目录网站索引
- pair make_pair
- java 执行sql文件