自动检索XML数据
2010-02-23 16:34
176 查看
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>
<!--
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(自动下载)
- VS2005 WINCE新建工程错误:从用户数据存储中检索信息时出错,XML文档必须包含一个顶层元素
- 请问如何在检索数据同时自动生成一个序号字段
- 代码自动生成(二)数据库表字段生成mybaties 映射配置文件**mapper.xml
- Enterprise Library 4.1数据访问应用程序块快速入门【7】在XML中进行多行检索
- 利用Microsoft.XMLHTTP定制页面无刷新自动检索提示信息
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(10):服务器端和客户端数据类型的自动转换:以XML方式序列化数据、小结
- xml用于非结构数据检索技术
- 《基于R语言的自动数据收集》--第3章 XML和JSON
- [ASP.net]从数据库中读取数据自动生成XML
- 结合XML的数据检索技术
- 强大的 将XML文件的数据导入到数据库的 程序 只需输入xml文件名即可自动创建
- 全文检索、数据挖掘、推荐引擎系列6---基于KMean的文本自动算法
- easyUI实现输入内容,自动检索数据
- dw子数据窗口dddw自动检索数据
- C# 利用FTP自动下载xml文件后利用 FileSystemWatcher 监控目录下文件变化并自动更新数据库
- Flex用HTTPService时加载xml或其它数据不自动刷新问题的解决方案
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(10):服务器端和客户端数据类型的自动转换:以XML方式序列化数据、小结
- MongoDB数据自动同步到ElasticSearch(实现中文全文检索)
- XMLHTTP无刷新自动实时更新数据