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.