各位大峡,我不知道为什么,运行得不到数据,我测试elmDoc.length总是0,但是我的xml里有数据啊! 是不是还需要配置什么东西??
nowDada.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<elmDoc>
<singleCur>
<id>1</id>
<curid>1.11</curid>
<buy>1.2</buy>
<sell>1.111111</sell>
</singleCur>
<singleCur>
<id>2</id>
<curid>2</curid>
<buy>1.7591999769210815</buy>
<sell>1.0</sell>
</singleCur>
<singleCur>
<id>3</id>
<curid>3</curid>
<buy>0.7483000159263611</buy>
<sell>0.0</sell>
</singleCur>
<singleCur>
<id>4</id>
<curid>4</curid>
<buy>116.4800033569336</buy>
<sell>0.0</sell>
</singleCur>
<singleCur>
<id>5</id>
<curid>5</curid>
<buy>1.13510000705719</buy>
<sell>0.0</sell>
</singleCur>
<singleCur>
<id>6</id>
<curid>6</curid>
<buy>1.2098000049591064</buy>
<sell>0.0</sell>
</singleCur>
<singleCur>
<id>7</id>
<curid>7</curid>
<buy>7.759900093078613</buy>
<sell>0.0</sell>
</singleCur><singleCur>
<id>8</id>
<curid>8</curid>
<buy>0.6633999943733215</buy>
<sell>0.0</sell>
</singleCur>
</elmDoc>
nowDada.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<elmDoc>
<singleCur>
<id>1</id>
<curid>1.11</curid>
<buy>1.2</buy>
<sell>1.111111</sell>
</singleCur>
<singleCur>
<id>2</id>
<curid>2</curid>
<buy>1.7591999769210815</buy>
<sell>1.0</sell>
</singleCur>
<singleCur>
<id>3</id>
<curid>3</curid>
<buy>0.7483000159263611</buy>
<sell>0.0</sell>
</singleCur>
<singleCur>
<id>4</id>
<curid>4</curid>
<buy>116.4800033569336</buy>
<sell>0.0</sell>
</singleCur>
<singleCur>
<id>5</id>
<curid>5</curid>
<buy>1.13510000705719</buy>
<sell>0.0</sell>
</singleCur>
<singleCur>
<id>6</id>
<curid>6</curid>
<buy>1.2098000049591064</buy>
<sell>0.0</sell>
</singleCur>
<singleCur>
<id>7</id>
<curid>7</curid>
<buy>7.759900093078613</buy>
<sell>0.0</sell>
</singleCur><singleCur>
<id>8</id>
<curid>8</curid>
<buy>0.6633999943733215</buy>
<sell>0.0</sell>
</singleCur>
</elmDoc>
解决方案 »
- 字符串截取
- 一个抽象类的问题
- 急救!。。JDBC连接sql出现错误!。。。。。
- ClassLoader的问题,虚心请教!!![java.lang.ClassFormatError]
- JTabbedPane导致JPanel频繁调用paint
- 我想找一个java的md5加密文件的源代码
- 拿最后10分提问题,请大家不要见笑……关于private
- 如何用JDK的api获得xml文件的一部分?
- feiyuegaoshan(飞跃)网友,请来接分!
- 我下载了经javax.sql包,但我不知道如何才能让jbuilder认出来
- 求助,JAVA下数据结构的汉诺塔小程序,已有基本代码!
- [求助]javax.swing.JTextField控件的右键菜单问题
<%@page contentType="text/html;charset=gb2312" language="java" errorPage="" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="javascript">
var http_request = false;
function send_request(url) {//初始化、指定处理函数、发送请求的函数
http_request = false;
//开始初始化XMLHttpRequest对象
if(window.XMLHttpRequest) { //Mozilla 浏览器
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {//设置MiME类别
http_request.overrideMimeType('text/xml');
}
}
else if (window.ActiveXObject) { // IE浏览器
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) { // 异常,创建对象实例失败
window.alert("不能创建XMLHttpRequest对象实例.");
return false;
}
http_request.onreadystatechange = processRequest;
// 确定发送请求的方式和URL以及是否同步执行下段代码
http_request.open("GET", url, false);
http_request.send();
setTimeout("send_request('"+url+"')",2000);
}
// 处理返回信息的函数
function processRequest() {
if (http_request.readyState == 4) { // 判断对象状态
if (http_request.status == 200) { // 信息已经成功返回,开始处理信息
var xmlobj = http_request.responseXML;
var elmDoc = xmlobj.getElementsByTagName("singleCur");
alert(elmDoc.length);
if(document.body.firstChild!=null){
document.body.removeChild(document.body.firstChild);
//alert("del");//test
}
var table=document.createElement("table");
table.setAttribute("border","1");
table.setAttribute("width","100%");
table.setAttribute("cellspacing",0);
table.setAttribute("cellpadding",0);
var head=table.createTHead();
var headrow=head.insertRow(0);
headrow.insertCell(0).appendChild(document.createTextNode("货币"));
headrow.insertCell(1).appendChild(document.createTextNode("买价"));
headrow.insertCell(2).appendChild(document.createTextNode("卖价"));
for(var i=0;i<elmDoc.length;i++) { // 循环读取
var singleCur = elmDoc[i];
row=table.insertRow(i+1);
row.insertCell(0).appendChild(document.createTextNode(
singleCur.getElementsByTagName("curid")[0].firstChild.data));
row.insertCell(1).appendChild(document.createTextNode(
singleCur.getElementsByTagName("buy")[0].firstChild.data));
row.insertCell(2).appendChild(document.createTextNode(
singleCur.getElementsByTagName("sell")[0].firstChild.data));
}
document.body.appendChild(table);
} else { //页面不正常
alert("您所请求的页面有异常。" + http_request.status);
}
}
}
</script>
</head>
<body onload="send_request('nowData.xml')">
</body>
</html>
if (http_request.status == 200) { // 信息已经成功返回,开始处理信息
var xmlobj = http_request.responseXML;
var elmDoc = xmlobj.getElementsByTagName("singleCur");
alert(elmDoc.length);//******总是0 ,但是在IIS下运行没有问题。******
--改成物理路径也不可以。我尝试如下alert(http_request.responseXML);-----[object]
alert(http_request.responseText);-----**能把整个nowData.xml 中的信息都显示出来**
奇怪?!
<%@page contentType="text/html;charset=utf-8" language="java" errorPage="" %>
<%@page contentType="text/html;charset=utf-8" language="java" errorPage="" %>
---尝试过了 ,还是没有效果。
为何
http_request.responseText--能够显示出所有节点
http_request.responseXML--还是一个对象。
http_request.getElementsByTagName("singleCur")--<<<---不能正确解释???!
我用的是Jbulider开发的。jdk1.42 tomcat4.12。
iis下运行征程,tomcat跑不了。
我想使用Ajax取出动态生成的XML,可是服务器中存在了生成的XML文件,
alert(xmlhttp.responseText);
确没有任何数据,好郁闷啊~~~