<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<SCRIPT LANGUAGE="JavaScript">
var elm_values = [] ;
var elm_texts = [];
var elm1_id ;
var elm_descs = [];
var elm_ids =[];
var elm_types =[];
var elm_readonlys =[];
var elm_relateds =[];
var elm_validate = [];
function doXml()
{
if (window.ActiveXObject){
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false; //Enforce download of XML file first. IE only.
}else if (document.implementation && document.implementation.createDocument){
var xmlDoc= document.implementation.createDocument("","doc",null);
}
if (typeof xmlDoc!="undefined")
xmlDoc.load("elms.xml");
//获取信息:
var a = xmlDoc.getElementsByTagName('element');
for(var i=0;i<a.length;i++){
elm_descs.push(a.item(i).getAttribute('desc'));
elm_ids.push(a.item(i).getAttribute('id'));
elm_types.push(a.item(i).getAttribute('type'));
elm_readonlys.push(a.item(i).getAttribute('readonly'));
elm_relateds.push(a.item(i).getAttribute('related_diaplay'));
}
var opt_value=xmlDoc.documentElement.selectSingleNode("//list").childNodes;
for(var i=0;i<opt_value.length;i++){
elm_texts.push(opt_value.item(i).text);
elm_values.push(opt_value.item(i).getAttributeNode("value").text);
}
//输出到页面
var tab = document.createElement("table");
tab.border =1;
var tbody = document.createElement("tbody");
var tr = document.createElement("tr");
for(var i=0;i<elm_ids.length;i++){
var td1 = document.createElement("td");
var tname =document.createTextNode(elm_descs[i]);
td1.appendChild(tname);
var td2 = document.createElement("td");
var input =document.createElement("input");
input.setAttribute("type",elm_types[i]);
input.setAttribute("id",elm_ids[i]);
if(elm_readonlys[i] !="undefined")input.readOnly = elm_readonlys[i];
if(elm_relateds[i] !="undefined")
{
input.setAttribute('onchange',document.all ? eval(function(){check(this.value)}) : 'javascript:check(this.value)');
elm1_id=elm_relateds[i];
//var str = elm_ids[i]+'-'+elm_relateds[i];
//alert(str);
//elm_validate.push(str);
}
td2.appendChild(input);
tr.appendChild(td1);
tr.appendChild(td2);
}
tbody.appendChild(tr);
tab.appendChild(tbody);
document.getElementById('show').appendChild(tab);
}
//动态赋值
function check(a){
for(var i=0;i<elm_values.length;i++){
if(a == elm_values[i])
document.getElementById(elm1_id).value = elm_texts[i];
}
}
</SCRIPT>
<BODY onload="doXml();">
<div id="show"></div>
</BODY>
</HTML>