如 xml中写:
<?xml version="1.0" encoding="utf-8" ?>
<config>
<serv_ip>192.168.0.105</serv_ip>
<database>test</database>
<userid>sa</userid>
<password>123456</password>
</config>
那么代码:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("config.xml");
XmlNode root = xmlDoc.SelectSingleNode("config");//指向根节点
XmlNode xn = root.SelectSingleNode("serv_ip");//指向根节点下的serv_ip节点
string ip = xn.InnerText;//读出里面的值 注意读取的是string 需要类型转换的话自己做
XmlNode database = root.SelectSingleNode("database");
string data = database.InnerText;
XmlNode userid = root.SelectSingleNode("userid");
string user = userid.InnerText;
XmlNode password = root.SelectSingleNode("password");
string pwd = password.InnerText;