<html>
<head>
</head>
<script language="javascript">
var XMLHttpReq = false;
function createXMLHttpRequest()
{
if(window.XMLHttpRequest)
{
XMLHttpReq = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
try
{
XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e)
{
try
{
XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e)
{}
}
}
}
function sendRequest(url)
{
createXMLHttpRequest();
XMLHttpReq.open("GET",url,true);
XMLHttpReq.onreadystatechange = processResponse;
XMLHttpReq.send(null);
}
function processResponse()
{
if(XMLHttpReq.readystate == 4)
{
if(XMLHttpReq.status == 200 || XMLHttpReq.status == 0)
{
var requestMsg=XMLHttpReq.responseText;
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
xmlDoc.loadXML(requestMsg);
//获得属性值
var aId = xmlDoc.getElementsByTagName("p").item(0).getAttribute("id");
var aName = xmlDoc.getElementsByTagName("p").item(1).getAttribute("id");
//获得节点内容值
var p1Text = xmlDoc.getElementsByTagName("p").item(0).text;
var p2Text = xmlDoc.getElementsByTagName("p").item(1).text;
document.getElementById("squlareIDAttr").value = aId;
document.getElementById("squlareNameIDAttr").value = aName;
document.getElementById("squlareID").value = p1Text;
document.getElementById("squlareNameID").value = p2Text;
}
}
}
function getSqulareInfo()
{
sendRequest("test.xml");
}
</script>
<body>
<table>
<tr>
<td>
甲方编码属性:
</td>
<td>
<input type="text" id="squlareIDAttr" name="squlareIDAttr" size="20" />
</td>
</tr>
<tr>
<td>
甲方名称属性:
</td>
<td>
<input type="text" id="squlareNameIDAttr" name="squlareNameIDAttr" />
</td>
</tr>
<tr>
<td>
甲方编码:
</td>
<td>
<input type="text" id="squlareID" name="squlareID" size="20" />
</td>
</tr>
<tr>
<td>
甲方名称:
</td>
<td>
<input type="text" id="squlareNameID" name="squlareNameID" />
</td>
</tr>
<TR>
<input type="button" name="ok" id="ok" value="确定" onclick="getSqulareInfo();"/>
</TR>
</table>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<html>
<head>
</head>
<body>
<p id="1111111">aaaaaaa</p>
<p id="2222222">bbbbbbb</p>
</body>
</html>