Use C # read, add, modify, and delete the XML file content.
Userbasicinfo.xml
XML Version = "1.0"?>
Controlxml.cs
// Read, add, modify, delete nodes use system.xml; use system;
Namespace Xmlteest.accessXml {///
Xmldoc = new xmldocument (); xmldoc.load ("D: //study//c///winform///xmlteest//userbasicinfo.xml");} public void readnode () {XMLNode XNRoot = XmlDoc.documentelement; // Get the only root node that is represented.
XmlNodeList xnlUserInfo = xnRoot.ChildNodes; // Get the child nodes of the root foreach (XmlNode xnTheUser in xnlUserInfo) {XmlNodeList xnlUserSub = xnTheUser.ChildNodes;. Foreach (XmlNode xnSub in xnlUserSub) {Console.WriteLine (xnSub.InnerText); // Display sub-node text} console.writeline ("------------------");}} public void addnode (String Userguid, String UserID, String Userpassword , string userQuestion, string userAnwser, string userName, string userSex, string userBirth, string userEmail, string userContactInfo) // Add node {// XmlNamespaceManager nsmgr = new XmlNamespaceManager (xmlDoc.NameTable);. XmlNode xnRoot = xmlDoc.DocumentElement; // Find
XMLELEMENT XESUB1 = XMLDoc.createElement ("Userguid"); Xesub1.innertext = UserGuID; // Node. User Unique Identification XEUSERINFO.APpendCHILD (XESUB1); // Add to the
XMLELEMENT XESUB2 = XMLDoc.createElement ("UserID"); Xesub2.innertext = UserId; // Node. User ID XEUSERINFO.APpendChild (Xesub2); // Add to
XMLELEMENT XESUB3 = XMLDoc.createElement ("Userpassword"); Xesub3.innertext = Userpassword; // Node. User Password XEUSERINFO.APpendChild (Xesub3); // Add to
XMLELEMENT XESUB4 = XMLDoc.createElement ("UserQuestion");
Xesub4.innertext = UserQuestion; Node. User Password prompt xEUserInfo.apndchild (Xesub4); // Add to the USERINFO node.
XMLELEMENT XESUB5 = XMLDoc.createElement ("UseranWser"); Xesub5.innertext = UseRanWser; // Node. User Password Answer XEUSERINFO.APpendChild (Xesub5); // Add to
XmlElement xesub6 = xmlDoc.CreateElement ( "userName"); xesub6.InnerText = userName; // node username xeUserInfo.AppendChild (xesub6);. // Add to
XMLELEMENT XESUB9 = XMLDoc.createElement ("Useremail"); Xesub9.innertext = Useremail; // User Email XEUSERINFO.APpendChild (Xesub9); // Add to
XMLELEMENT XESUB10 = XMLDoc.createElement ("UserContactInfo"); Xesub10.innertext = UserContactInfo; XEUSERINFO.APPENDCHILD (XESUB10);
XnRoot.Appendchild (XEUSERINFO); // Add
XMLDoc.save ("D: //study//c///winform//xmlteest///userbasicinfo.xml");