JS读取Xml文件节点属性
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<style type="text/css">
table,tr,td {
background-position: center;
border-width: 1px;
border-style: solid;
border-collapse: collapse;
border-color: blue;
text-align: center;
font-size: 20px;
}
table {
width: 600px;
margin-bottom: 10px;
}
tr {
height: 30px;
}
.bordertyle {
font-family: sans-serif;
text-align: center;
}
.btn {
margin-left: 30px;
margin-right: 30px;
}
label {
font-size: 20px;
font-family: sans-serif;
}
</style>
<script language="javascript" type="text/javascript">
//***********js操作XML*************
//* author:luobin *
//* Email:luobin23628@163.com *
//*********************************
/*
function loadXML(xmlFile){
var xmlDoc;
if(!window.ActiveXObject){
var parser = new DOMParser();
xmlDoc = parser.parseFromString(xmlFile,"text/xml");
}else{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.load(xmlFile);
}
return xmlDoc;
}
*/
//针对两种浏览器,分别获取xmlDocument对象
function loadXML(xmlFile)
{
var xmlDoc;
if(window.ActiveXObject) {
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load(xmlFile);
}
else if(document.implementation&&document.implementation.createDocument){
xmlDoc=document.implementation.createDocument( "", "",null);
xmlDoc.async=false;
xmlDoc.load(xmlFile);
} else{
alert('Your browser cannot handle this script');
}
return xmlDoc;
}
var xmlDoc = loadXML("custInfo.xml");
var members = xmlDoc.getElementsByTagName("custNo");
var maxRes = members.length;
var pageShow = 5;
var currentPage = 1;
var maxPage = Math.ceil(maxRes/pageShow);
//此方法只能在body标签中或后调用
function retrieve(){
var oDiv = document.createElement("div");
oDiv.id = "showhtml"
oDiv.className = "bordertyle";
if(maxRes){
var oTable = generateTable(oDiv,(currentPage-1)*pageShow,currentPage*pageShow);
var pageInf = document.createElement("div");
var oLabel = document.createElement("label");
oLabel.innerHTML = "共条"+maxRes+"记录,当前第";
pageInf.appendChild(oLabel);
var curLabel = document.createElement("label");
curLabel.innerHTML = currentPage;
curLabel.setAttribute("id","curLabel");
pageInf.appendChild(curLabel);
var oLabel3 = document.createElement("label");
oLabel3.innerHTML = "页,共"+maxPage+"页";
pageInf.appendChild(oLabel3);
oDiv.appendChild(pageInf);
var buttonSet = document.createElement("div")
buttonSet.className = "bordertyle";
var firstBtn = document.createElement("button");
firstBtn.innerHTML = "首页";
firstBtn.id = "firstBtn";
firstBtn.className = "btn";
firstBtn.onclick = function(){
goToPage(1,oTable,curLabel);
};
buttonSet.appendChild(firstBtn);
var preBtn = document.createElement("button");
preBtn.id = "preBtn";
preBtn.inn