高分求JS读取二级XML
<?xmlversion="1.0"encoding="UTF-8"?><aaa><bbbtitle="ccc"><itemID="001"title="123"/><i...
<?xml version="1.0" encoding="UTF-8"?>
<aaa>
<bbb title="ccc">
<item ID="001" title="123" />
<item ID="002" title="123" />
</bbb>
<bbb title="ddd">
<item ID="003" title="123" />
<item ID="004" title="123" />
</bbb>
<bbb title="eee">
<item ID="005" title="123" />
<item ID="006" title="123" />
</bbb>
</aaa>
很简单,读取这个XML里的<item>的ID和Title属性,然后写入到一个二维数组里。
高分求这段JS代码,不要随便找篇文章贴过来啦,是要给出实现代码的。 展开
<aaa>
<bbb title="ccc">
<item ID="001" title="123" />
<item ID="002" title="123" />
</bbb>
<bbb title="ddd">
<item ID="003" title="123" />
<item ID="004" title="123" />
</bbb>
<bbb title="eee">
<item ID="005" title="123" />
<item ID="006" title="123" />
</bbb>
</aaa>
很简单,读取这个XML里的<item>的ID和Title属性,然后写入到一个二维数组里。
高分求这段JS代码,不要随便找篇文章贴过来啦,是要给出实现代码的。 展开
展开全部
xmlHttp.responseBody);
var doc = new ActiveXObject("MSXML2.DOMDocument");
doc.loadXML(xmlHttp.responseTEXT);
var arr = new Array();
var item = doc.getElementsByTagName("item");
for (var i = 0; i < item.length; i++) {
arr[i] = new Array();
arr[i].push("</br>" + item[i].getAttribute("ID"));
arr[i].push(item[i].getAttribute("title"));
}
document.getElementsByTagName("span")[0].innerHTML = arr; //arr[0][0];
}
}
}
} catch (exception) {
document.write('exception:' + exception.message);
var doc = new ActiveXObject("MSXML2.DOMDocument");
doc.loadXML(xmlHttp.responseTEXT);
var arr = new Array();
var item = doc.getElementsByTagName("item");
for (var i = 0; i < item.length; i++) {
arr[i] = new Array();
arr[i].push("</br>" + item[i].getAttribute("ID"));
arr[i].push(item[i].getAttribute("title"));
}
document.getElementsByTagName("span")[0].innerHTML = arr; //arr[0][0];
}
}
}
} catch (exception) {
document.write('exception:' + exception.message);
展开全部
<html>
<head>
<script>
var xmlHttp;
var rs;
var isie = false;
function startRequest(url, divs) {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
isie = true;
} else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
try {
if (isie == false) {
xmlHttp.open("GET", url, false);
xmlHttp.overrideMimeType("text/html;charset=utf-8");
xmlHttp.send(null);
document.getElementById(divs).innerHTML = xmlHttp.responseText;
} else {
xmlHttp.open("GET", url, false);
xmlHttp.send(null);
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200 || xmlHttp.status == 0) {
document.getElementById(divs).innerHTML = Recenspace(xmlHttp.responseBody);
var doc = new ActiveXObject("MSXML2.DOMDocument");
doc.loadXML(xmlHttp.responseTEXT);
var arr = new Array();
var item = doc.getElementsByTagName("item");
for (var i = 0; i < item.length; i++) {
arr[i] = new Array();
arr[i].push("</br>" + item[i].getAttribute("ID"));
arr[i].push(item[i].getAttribute("title"));
}
document.getElementsByTagName("span")[0].innerHTML = arr; //arr[0][0];
}
}
}
} catch (exception) {
document.write('exception:' + exception.message);
}
}
function Recenspace(Html) {
rs = new ActiveXObject("ADODB.RecordSet");
rs.fields.append("a", 201, 1);
rs.open();
rs.addNew();
rs(0).appendChunk(Html);
rs.update();
return rs(0).value;
rs.close();
}
function show() {
var r = document.getElementById("postfile").value;
startRequest(r, 'showspan');
}
</script>
</head>
<body>
<div style="width: 1004px; text-align: center;">
<span id="showspan"></span>
</div>
<div style="width: 1004px; text-align: center;">
<input id="postfile" type="file" onchange="show()" />
</div>
</body>
</html>
-------------------------
输出:
001,123,
002,123,
003,123,
004,123,
005,123,
006,123
<head>
<script>
var xmlHttp;
var rs;
var isie = false;
function startRequest(url, divs) {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
isie = true;
} else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
try {
if (isie == false) {
xmlHttp.open("GET", url, false);
xmlHttp.overrideMimeType("text/html;charset=utf-8");
xmlHttp.send(null);
document.getElementById(divs).innerHTML = xmlHttp.responseText;
} else {
xmlHttp.open("GET", url, false);
xmlHttp.send(null);
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200 || xmlHttp.status == 0) {
document.getElementById(divs).innerHTML = Recenspace(xmlHttp.responseBody);
var doc = new ActiveXObject("MSXML2.DOMDocument");
doc.loadXML(xmlHttp.responseTEXT);
var arr = new Array();
var item = doc.getElementsByTagName("item");
for (var i = 0; i < item.length; i++) {
arr[i] = new Array();
arr[i].push("</br>" + item[i].getAttribute("ID"));
arr[i].push(item[i].getAttribute("title"));
}
document.getElementsByTagName("span")[0].innerHTML = arr; //arr[0][0];
}
}
}
} catch (exception) {
document.write('exception:' + exception.message);
}
}
function Recenspace(Html) {
rs = new ActiveXObject("ADODB.RecordSet");
rs.fields.append("a", 201, 1);
rs.open();
rs.addNew();
rs(0).appendChunk(Html);
rs.update();
return rs(0).value;
rs.close();
}
function show() {
var r = document.getElementById("postfile").value;
startRequest(r, 'showspan');
}
</script>
</head>
<body>
<div style="width: 1004px; text-align: center;">
<span id="showspan"></span>
</div>
<div style="width: 1004px; text-align: center;">
<input id="postfile" type="file" onchange="show()" />
</div>
</body>
</html>
-------------------------
输出:
001,123,
002,123,
003,123,
004,123,
005,123,
006,123
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询