function display(){ var doc=xmldso.XMLDocument; alert(doc.xml); }
function save(){ try{ var doc=xmldso.XMLDocument; alert(doc.xml); var strFile=""; var fso, f, ts; var s="E:\\緲掋亞\\XML\\javascript_ReadWriteXML\\studentinfo.xml"; var ForReading = 1, ForWriting = 2, ForAppending = 8; var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0; fso = new ActiveXObject("Scripting.FileSystemObject"); if(!fso.FileExists(s)){ alert(s+" is not exist!"); }else{ f = fso.GetFile(s); ts = f.OpenAsTextStream(ForWriting, TristateUseDefault); ts.WriteLine(doc.xml); ts.Close( ); } }catch(e){ alert(e); }
}
//澧炲姞??錛? function addID(){ var doc=xmldso.XMLDocument; var rootnode=doc.documentElement; var sortNode = rootnode.selectNodes("http://id"); var currentid = sortNode.length-1; var cc=""; if(currentid==-1){ var node= studentinfoNew.documentElement.childNodes(0).cloneNode(true); xmldso.documentElement.appendChild(node); }else{ cc=sortNode.item(currentid).text; if ((cc=="aa")||(cc=="")){ alert("?灝嗘渶鍚庝竴琛屾暟鎹~鍐欏畬?鍚庡啀澧炲姞鏂扮殑??錛?); }else{ var node= studentinfoNew.documentElement.childNodes(0).cloneNode(true); xmldso.documentElement.appendChild(node); } } } //?闄?? function delID(whichFld){ var doc=xmldso.XMLDocument; var rootnode=doc.documentElement; var sortNode = rootnode.selectNodes("http://student"); if(sortNode.length==1){ alert("can not do delete when there is only 1 record"); return; }
var sortNode = xmldso.selectSingleNode("http://student/id[text()='"+whichFld+"']"); try{ sortNode.parentNode.parentNode.removeChild(sortNode.parentNode); }catch(e){ } } </SCRIPT>
function createfile(){ if(check()==false)return false; var name=document.getElementById("name").value; var name1=name.split("."); if(name1[1]==undefined)name=name+".txt"; //alert(name); pathAndName=document.getElementById("path").value+name; //alert(pathAndName); var fso=new ActiveXObject("Scripting.FileSystemObject"); var f1=fso.createTextFile(pathAndName); if(!f1)alert("鏂囦歡鍒涘緩澶辮觸"); else alert("鏂囦歡鎴愬姛鍒涘緩錛屼笅闈㈢戶緇啓鍏ュ唴瀹?); f1.Write(document.getElementById("content").value); if(f1.read()!="")alert("鍐呭宸茬粡鍐欏叆"); f1.close(); }
function readfile(){ if(checkRead()==false)return false; var name=document.getElementById("name").value; var name1=name.split("."); if(name1[1]==undefined)name=name+".txt"; //alert(name1[1]); pathAndName=document.getElementById("path").value+name; //alert(pathAndName); var fso=new ActiveXObject("Scripting.FileSystemObject"); var f2 try{ f2=fso.openTextFile(pathAndName); }catch(e){alert(name+"娌℃壘鍒?);} var a=""; while (!f2.AtEndOfStream){ a += f2.ReadLine( );} f2.Close( ); content.innerHTML=a; alert("瀹冪殑浣嶇疆鍦?+pathAndName); } function check(){ if(document.getElementById("name").value==""||document.getElementById("content").value=="") {alert("鏂囦歡鍚嶅拰鍐呭閮戒笉鑳戒負絀猴紒"); document.getElementById("name").focus(); return false;}