Published on blog.csdn.net/zxub
Function SaveFile (filename, xmlstr) // Save the text file
{
VaR FSO, TF, F;
FSO = new activexobject ("scripting. FileSystemObject ");
Try
{
F = FSO. GetFile (filename );
F. Attributes = 0;
}
Catch (e ){}
TF = FSO. createtextfile (filename, true );
TF. Write (xmlstr );
TF. Close ();
}
Function createdom (xmlstr)
{
VaR dom = new activexobject ("msxml2.domdocument. 3.0 ");
// Create a DOM instance and load the file
Dom. async = "false ";
Dom. loadxml (xmlstr );
Return Dom;
}
Function setvaluebyname (ptagname, pkeyname, pvalue)
{
VaR xmldom = createdom (openfile (getxmlfilepath ()));
VaR pnodelist = xmldom. getelementsbytagname (ptagname );
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 ("<? XML version = \ "1.0 \"?> "," <? XML version = \ "1.0 \" encoding = \ "gb2312 \"?> ")
SaveFile (getxmlfilepath (), xmlstr );
}
Function getvaluebyname (ptagname, pkeyname)
{
VaR xmldom = createdom (openfile (getxmlfilepath ()));
VaR pnodelist = xmldom. getelementsbytagname (ptagname );
VaR pchildnode = pnodelist. Item (0). firstchild;
VaR pvalue = 100;
For (j = 1; j ++)
{
If (pchildnode. nodename = pkeyname)
{
Pvalue = pchildnode. text;
Return pvalue;
Break;
}
Pchildnode = pchildnode. nextsibling;
}
}