Question : Read/Write XML

Ok I am trying to display information in an XML file. I have a form (view attached image Form 3) which I want the user to be able to view or edit. Basically I want the application to act like this. The admin logs in and opens Form 3. When it opens the default information to display in the textbox based upon what is in the default XML file. Then I want the admin to be able to edit the IP Address, IP Port, and the Configuration Pathway. Can some one please help me with the first part of this which is taking the default information in the XML File and displaying it in the text boxes? After that I tackle the second half.

My XML File code is below in addition to the form code that I have so far.

Answer : Read/Write XML

Thanks, seahna. There are of course a lot of ways to do this, and I don't know that mine is better than some of the other suggestions. Since you want to focus on reading the XML file into the form, I'll just deal with that right now.

Obviously I'm making up the names of your textboxes, but this should point you in the right direction.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
public void PopulateServerForm()
{
  XmlDocument myDoc = new XmlDocument();
  myDoc.Load(@"C:\myFile.xml");
  string ipAddressXpath = string.Format("Setup/ACSP/Primary/IPAddress");
  string ipPortXpath = string.Format("Setup/ACSP/Primary/IPPort");
  string configPathXpath = string.Format("Setup/ACSP/Primary/ConfigurationPath");
  txtIPAddress.Text = ReadValueFromXmlDocumentAtXPath(myDoc, ipAddressXpath);
  txtIPPort.Text = ReadValueFromXmlDocumentAtXPath(myDoc, ipPortXpath);
  txtConfigPath.Text = ReadValueFromXmlDocumentAtXPath(myDoc, configPathXpath);
}

public string ReadValueFromXmlDocumentAtXPath(XmlDocument myDoc, string xpath)
{
  string value = string.Empty;
  XmlNode myNode= myDoc.SelectSingleNode(xpath);
  if(myNode != null && myNode.InnerText != null)
  {
    value = myNode.InnerText;
  }
  return value;
}
Random Solutions  
 
programming4us programming4us