Determine whether an XML file exists. If it does not exist, create an XML file. If it exists, add it to it.

Source: Internet
Author: User

If (file. exists (xmlpath + "\" + xmlname) // checks whether the file is in the {// state. xmldocument xmldoc = new xmldocument (); xmldoc. load (xmlpath + "\" + xmlname); // The xmlnode root = xmldoc file exists. selectsinglenode ("History"); xmlelement Bak = xmldoc. createelement_x ("Bak"); root. appendchild (BAK );

Xmlelement baktime = xmldoc. createelement_x ("baktime"); baktime. innertext = datetime. Now. tostring (); Bak. appendchild (baktime); // backup time

Xmlelement bakname = xmldoc. createelement_x ("bakname"); bakname. innertext = dbfilename; Bak. appendchild (bakname); // backup name

Xmlelement datasource = xmldoc. createelement_x ("datasource"); datasource. innertext = datasource; Bak. appendchild (datasource); // Data Source

Xmlelement database = xmldoc. createelement_x ("Database"); database. innertext = database; Bak. appendchild (database); // Database Name

Xmlelement databaseuser = xmldoc. createelement_x ("userid"); databaseuser. innertext = userid; Bak. appendchild (databaseuser); // database username

Xmlelement Password = xmldoc. createelement_x ("password"); password. innertext = password; Bak. appendchild (password); // Database Password

Xmlelement username = xmldoc. createelement_x ("staffname"); username. innertext = staffname; Bak. appendchild (username); // backup person

Xmldoc. Save (xmlpath + "\" + xmlname );

} Else {// The file directory. createdirectory (xmlpath) does not exist; // create the file

Xmldocument xmldoc = new xmldocument ();

Xmlnode = xmldoc. createxmldeclaration ("1.0", "gb2312", null); xmldoc. appendchild (xmlnode );

Xmlelement root = xmldoc. createelement_x ("History"); xmldoc. appendchild (Root); xmlelement Bak = xmldoc. createelement_x ("Bak"); root. appendchild (BAK );

Xmlelement baktime = xmldoc. createelement_x ("baktime"); baktime. innertext = datetime. Now. tostring (); Bak. appendchild (baktime); // backup time

Xmlelement bakname = xmldoc. createelement_x ("bakname"); bakname. innertext = dbfilename; Bak. appendchild (bakname); // backup name

Xmlelement datasource = xmldoc. createelement_x ("datasource"); datasource. innertext = datasource; Bak. appendchild (datasource); // Data Source

Xmlelement database = xmldoc. createelement_x ("Database"); database. innertext = database; Bak. appendchild (database); // Database

Xmlelement databaseuser = xmldoc. createelement_x ("userid"); databaseuser. innertext = userid; Bak. appendchild (databaseuser); // database username

Xmlelement Password = xmldoc. createelement_x ("password"); password. innertext = password; Bak. appendchild (password); // Database Password

Xmlelement username = xmldoc. createelement_x ("staffname"); username. innertext = staffname; Bak. appendchild (username); // backup person

Xmldoc. Save (xmlpath + "\" + xmlname );}

Determine whether an XML file exists. If it does not exist, create an XML file. If it exists, add it to it.

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.