日期:2014-05-16 浏览次数:20740 次
String strxml= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; strxml=strxml+ "<message><info>not file data! </info></message>"; //response.getWriter().write(strxml);
<%@ page contentType="text/html; charset=GBK"%> <%@ page import="java.io.*" %> <% String filename = request.getRealPath("main.xml"); java.io.File f = new java.io.File(filename); if (f.exists()) { int length = 0; char [] buffer = new char[1024]; //out.write(buffer, 0, 1024); java.io.FileReader fr = new java.io.FileReader(f); length = fr.read(buffer); response.setContentType( "text/xml; charset=UTF-8"); response.setHeader("Cache-Control", "no-cache"); response.getWriter().write(buffer); fr.close(); String strxml= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; strxml=strxml+ "<message><info>not file data! </info></message>"; //response.getWriter().write(strxml); } else { out.write("File isn't exist!"); } %>
<?xml version="1.0" encoding="UTF-8"?> <note> <rid> RoadId: 1029</rid> <speed> Speed: 85.29</speed> <status> status: 2</status> <info> info: Blocked</info> </note>
function stateChanged() { if (xmlHttp_main.readyState==4 && xmlHttp_main.status==200) { var txt,x,i; txt=""; xmlDoc=xmlHttp_main.responseXML; if(xmlDoc != null) alert("xml:---"+xmlDoc); x=xmlDoc.getElementsByTagName("info"); txt=txt+x[0].firstChild.nodeValue+"<br />"; document.getElementById("txtHint").innerHTML=txt; } }