求救:xml解析到jsp上
现有一xml文件
<?xml version="1.0" encoding="GBK" ?>
<sysconfig>
<config key="starturl">asd</config>
<config key="mmfiledir" >12</config>
<config key="wincfgdir" >331</config>
</sysconfig>
解析到页面
<table width="80%" border="0" align="center" cellpadding="2" cellspacing="1" class="tableStyle01">
<tr>
<td align="right" class="TDstyle01">fileurl: </td>
<td class="TDstyle01"><input name="fileurl" type="text" class="input" ></td>
</tr>
<tr>
<td align="right" class="TDstyle01">starturl: </td>
<td class="TDstyle01"><input name="starturl" type="text" class="input" ></td>
</tr>
<tr>
<td align="right" class="TDstyle01">mmfiledir:</td>
<td class="TDstyle01"><input name="mmfiledir" type="text" class="input" style="width:80%" ></td>
</tr>
</table>
[解决办法]
楼主是想解析xml的内容然后填入页面上相应的文本框吗?
方式有很多啊
1,用一个servlet,在servlet里面进行xml的解析,然后将解析的结果进行返回,在这个页面进行取得所需数据就可以了
2,在页面加载的时候用js的方式进行xml的解析,并对text控件进行赋值
[解决办法]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> <script language="javascript"> function readXML(){ var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.load("text.xml"); var code=xmlDoc.getElementsByTagName("config"); for(var i=0;i<code.length;i++){ var nodename = code[i].getAttribute("key"); var nodevalue = code[i].firstChild.nodeValue; if(nodename == "starturl"){ document.getElementById("record2").value=nodevalue; }else if(nodename == "mmfiledir"){ document.getElementById("record3").value=nodevalue; }else if(nodename == "wincfgdir"){ document.getElementById("record1").value=nodevalue; } } } </script> </HEAD> <BODY onload="readXML();"> <form name="form1" > <table width="80%" border="0" align="center" cellpadding="2" cellspacing="1" class="tableStyle01"> <tr> <td align="right" class="TDstyle01">fileurl: </td> <td class="TDstyle01"> <input name="fileurl" type="text" class="input" id="record1" > </td> </tr> <tr> <td align="right" class="TDstyle01">starturl: </td> <td class="TDstyle01"> <input name="starturl" type="text" class="input" id="record2" > </td> </tr> <tr> <td align="right" class="TDstyle01">mmfiledir: </td> <td class="TDstyle01"> <input name="mmfiledir" type="text" class="input" style="width:80%" id="record3"> </td> </tr> </table> </BODY> </form></HTML>
[解决办法]
d:/sysconfig.xml这个路径,jsp是找不到的,如要实现你所说的功能,你要解析的XML文件需要在你的虚拟目录下才行,然后将该XML的绝对路径提交给2.JSP,路径如:http://localhost:8080/虚拟目录名/***.xml,然后在2.JSP中进行解析。
[解决办法]