Please give me the simplest way to read or modify the XML file data?
Currently I tried this but it throws an exception. My current code is:
XmlDocument xml = new XmlDocument();
xml.Load("server.xml");
XmlNodeList serverlist = xml.SelectNodes("//server");
foreach (XmlNode servernodes in serverlist)
{
string server_address = servernodes.SelectSingleNode("addresh").InnerText;
string server_uname = servernodes.SelectSingleNode("username").InnerText;
string server_psw = servernodes.SelectSingleNode("password").InnerText;
}
my XML is below:
<?xml version="1.0" ?>
<server>
<address>localhost</address>
<username>myuser</username>
<password>mypassword</password>
</server>
and Exception is:
NullReference Exception: "Object reference not set to an instance of an object."
What should i do?
Answer : I am correcteed the code in Question. Now it is 100% right.