When you start this question at first, I haven't introduced a lot of information. I don't know if it is a difficult technology I find anything. Is there anything I do? NO !! I spent a job, I finally solved this problem, I am happy to feel the practicality of the information on the Internet, just like this blog, put it up, I hope to help everyone.
Function OpenFile (filename) // Open text files, return file content with strings {VAR FSO, TS, S; var forreading = 1; fso = new activXObject ("scripting.filesystemObject"); ts = fso.opentextfile (filename, Forreading); s = ts.readall (); ts.close (); returnction s;} Function Savefile (filename, xmlstr) // Save text file {var FSO, TF, F; fso = new activxObject ("scripting.filesystemObject (" scripting.filesystemObject "); Try {f = fso.getfile (filename); f.attributes = 0;} catch (e) {} tf = fso.createtextfile (filename, true);
Tf.Write (Xmlstr); tf.close ();} Function SavexmlFile (PfilePath, XmLDom) / / {为 x 文件 文件 {var Xmlstr = xmldom.xml; xmlstr = xmlstr.replace (" xml version = /" 1.0 / "?>", " xml version = /" 1.0 / "encoding = /" GB2312 / "?>"); // alert (pfilepath "," xmlstr); savefile (pfilepath, xmlstr);} function LoadDom (filename) {var xmldoc = new activXObject ("msxml2.domdocument.3.0"); xmldoc.async = false; xmldoc.resolveexternals = false; xmldoc.load (filename); return xmldoc;
} // According to the XML string, create a DOM object function createdom ("msxml2.domdocument.3.0"); // Create a DOM instance, and load file Dom.async = "false"; DOM. loadXML (xmlStr); return dom;} function fileExist (FileFullPath) // determines whether a file exists {var fso = new ActiveXObject ( "Scripting.FileSystemObject"); if (fso.FileExists (FileFullPath)) {return true;} else { Return False;}}} Function CreateXMLCFG (PTAGNAME, PKEYNAME, PVALUE) // Create a new XML file containing related information {var xmlstr = " xml version = /" 1.0 / "encoding = /" gb2312 / "?> XMLSTR = "
Function addXmltag (ptagname, pkeyname, pvalue) // Insert a new node containing related information to the XML file {var xmldom = createdom (OpenFile ("UserDefine"))); var root = xmldom.documentelement; var infonode = XmlDom.createnode (1, ptagname, "); root.appendchild (infonode); var tempnode = null; var obj = null; tmpnode = xmldom.createnode (1, pkeyname," "); tmpnode.text = pValue; infonode .appendchild (tmpnode); var xmlstr = xmldom.xml; xmlstr = xmlstr.replace (" Xml version = /" 1.0 / "?>", " xml version = /" 1.0 / "encoding = /" GB2312 / "?>") Savefile ("UserDefine"), XMLSTR);} Function AddXmlKey (PVALUE) // Insert new information to the related nodes in XML {var xmldom = createdom (getxmlfilepath (" userdefine "))); var pNodeList = xmlDom.getElementsByTagName (pTagName); var pchildNode = pNodeList.item (0); var tmpNode = null; var obj = null; tmpNode = xmlDom.createNode (1, pKeyName," "); TmpNode.Text = PVALUE; PCHildNode.Appendchild (TmpNode); var xmlstr = xmldom.xml; xmlstr = xmlstr.replace (" xml version = /" 1.0 / "?>", " xml version = /" 1.0 / "encoding = /" GB2312 / "?>") Savefile ("UserDefine", XMLSTR);} Function getXmlFilePath (fileType) // Get the path to the configuration file: FileType represents the file type, Default is default.xml, userdefine is the same {var Dir = LOCATION .href.substring (0, location.href.lastindexof ('?') 1); var xmlfilepath = location.href.substring (Dir.Length, location.href.Length 1); XMLFilePath = XMLFilePath.Replace (" File: /// "," "" XMLFilePath = XMLFilePath.Substring (0, XMLFilePath.lastIndexof ("/"));
XmlFilePath = XmlFilePath.substring (0, XmlFilePath.lastIndexOf ( "/")); switch (FileType) {case "default": XmlFilePath = XmlFilePath "/ config / default.xml"; break; case "userdefine": XmlFilePath = XmlFilePath "/config/UserDefine.xml"; Break default: Alert ("Unclear is the default file or user custom file!"); Return False;} Xmlfilepath = XMLFilePath.Replace ("/", "//"); return XMLFILEPATH);
function setValueByName (FileType, pTagName, pKeyName, pValue) // XML file locator assignment {var xmlDom; if (fileExist (GetXmlFilePath (FileType))) {xmlDom = createDom (openFile (GetXmlFilePath (FileType)));} else {// Alert ("User Profile does not exist, create new files"); // Create file createXmlcfg (PTAGNAME, PKEYNAME, PVALUE); ALERT ("Saves modified information, will be made in the modified configuration, A4 paper printing!" Return;} try {var pnodelist = xmldom.GtelementsBytagname (ptagname); if (pnodelist.item (0) == null) {// alert ("There is no table information!"); Addxmltag (ptagname, pkeyname, PValue); Alert ("Saves modified information, will be printed in the modified configuration!"); return;} var pchildnode = pnodelist.item (0) .firstchild; for (j = 1; j ) {if (pchildNode.nodeName == pKeyName) {pchildNode.text = pValue; break;} pchildNode = pchildNode.nextSibling;} var xmlStr = xmlDom.xml; xmlStr = xmlStr.replace ( "?