Modify and read fields in XML [original]

Source: Internet
Author: User

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;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.