我有带有此代码的xml文件
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<applicationSettings>
<GlobalERP.UI.Properties.Settings>
<setting name="SQLServerIP" serializeAs="String">
<value>192.168.1.1</value>
</setting>
<setting name="SQLUserName" serializeAs="String">
<value>sa</value>
</setting>
<setting name="SQLPassword" serializeAs="String">
<value>123</value>
</setting>
<setting name="SQLDBName" serializeAs="String">
<value />
</setting>
</GlobalERP.UI.Properties.Settings>
</applicationSettings>
</configuration>
如何通过代码反序列化并通过“ SQLServerIP”或“ SQLUserName”之类的名称获取值并读取没有System.Configuration的行?
答案 0 :(得分:0)
我觉得最好 Answer 进行少量修改
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNodeList elemList = doc.GetElementsByTagName("setting");
for (int i = 0; i < elemList.Count; i++)
{
if (elemList[i].Attributes["name"].Value == "UserName")
{
textBox1.Text += elemList[i].InnerText;
}
}