下面是添加和删除。至于创建和修改还没有搞到。
add的代码是:
functionadded()
{varxmlDoc=newActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false"; xmlDoc.load("student.xml");
xmlroot=xmlDoc.documentElement; varelement=xmlDoc.createNode(1,"student",""); Subsname=xmlDoc.createNode(1,"sname","");
Subsaddress=xmlDoc.createNode(1,"saddress","");
Subshttp=xmlDoc.createNode(1,"shttp","")
Subsemail=xmlDoc.createNode(1,"semail","");
Substel=xmlDoc.createNode(1,"stel","");
Substextarea=xmlDoc.createNode(1,"stextarea",""); t2=xmlDoc.createTextNode(document.form2.t2.value);
t3=xmlDoc.createTextNode(document.form3.t3.value);
t4=xmlDoc.createTextNode(document.form4.t4.value);
t5=xmlDoc.createTextNode(document.form5.t5.value);
t6=xmlDoc.createTextNode(document.form6.t6.value);
t8=xmlDoc.createTextNode(document.form8.t8.value); element.setAttribute("id",document.form1.t1.value); Subsname.appendChild(t2); Subsaddress.appendChild(t3); Subshttp.appendChild(t4); Subsemail.appendChild(t5); Substel.appendChild(t6); Substextarea.appendChild(t8); element.appendChild(Subsname);
element.appendChild(Subsaddress);
element.appendChild(Subshttp);
element.appendChild(Subsemail);
element.appendChild(Substel); element.appendChild(Substextarea);
xmlroot.appendChild(element); //保存到磁盘中
varfso=newActiveXObject("Scripting.FileSystemObject");
varts=fso.createTextFile("e:\\xmls\\student.xml",true);
ts.write(xmlDoc.xml);
ts.close;
//用浏览器显示文件
}
remove的代码是:
functiondel(text)
{varxmlDoc=newActiveXObject("Microsoft.XMLDOM");
//alert(1)
xmlDoc.async="false";
//alert(1)
xmlDoc.load("student.xml");
//alert(0)
root=xmlDoc.documentElement;
nodes=root.childNodes;
vari;
//alert(0)
for(i=0;i {
node=nodes.item(i);
tid=nodes.item(i).getAttribute("id");
if(tid==text)
{
root.removeChild(node);
}
}
//保存到磁盘中
varfso=newActiveXObject("Scripting.FileSystemObject");
varts=fso.createTextFile("e:\\xmls\\student.xml",true);
ts.write(xmlDoc.xml);
ts.close;
//用浏览器显示文件
}
add的代码是:
functionadded()
{varxmlDoc=newActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false"; xmlDoc.load("student.xml");
xmlroot=xmlDoc.documentElement; varelement=xmlDoc.createNode(1,"student",""); Subsname=xmlDoc.createNode(1,"sname","");
Subsaddress=xmlDoc.createNode(1,"saddress","");
Subshttp=xmlDoc.createNode(1,"shttp","")
Subsemail=xmlDoc.createNode(1,"semail","");
Substel=xmlDoc.createNode(1,"stel","");
Substextarea=xmlDoc.createNode(1,"stextarea",""); t2=xmlDoc.createTextNode(document.form2.t2.value);
t3=xmlDoc.createTextNode(document.form3.t3.value);
t4=xmlDoc.createTextNode(document.form4.t4.value);
t5=xmlDoc.createTextNode(document.form5.t5.value);
t6=xmlDoc.createTextNode(document.form6.t6.value);
t8=xmlDoc.createTextNode(document.form8.t8.value); element.setAttribute("id",document.form1.t1.value); Subsname.appendChild(t2); Subsaddress.appendChild(t3); Subshttp.appendChild(t4); Subsemail.appendChild(t5); Substel.appendChild(t6); Substextarea.appendChild(t8); element.appendChild(Subsname);
element.appendChild(Subsaddress);
element.appendChild(Subshttp);
element.appendChild(Subsemail);
element.appendChild(Substel); element.appendChild(Substextarea);
xmlroot.appendChild(element); //保存到磁盘中
varfso=newActiveXObject("Scripting.FileSystemObject");
varts=fso.createTextFile("e:\\xmls\\student.xml",true);
ts.write(xmlDoc.xml);
ts.close;
//用浏览器显示文件
}
remove的代码是:
functiondel(text)
{varxmlDoc=newActiveXObject("Microsoft.XMLDOM");
//alert(1)
xmlDoc.async="false";
//alert(1)
xmlDoc.load("student.xml");
//alert(0)
root=xmlDoc.documentElement;
nodes=root.childNodes;
vari;
//alert(0)
for(i=0;i {
node=nodes.item(i);
tid=nodes.item(i).getAttribute("id");
if(tid==text)
{
root.removeChild(node);
}
}
//保存到磁盘中
varfso=newActiveXObject("Scripting.FileSystemObject");
varts=fso.createTextFile("e:\\xmls\\student.xml",true);
ts.write(xmlDoc.xml);
ts.close;
//用浏览器显示文件
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货