怎么用 xml 写一个简单的软件自动更新配置文件出来(愚翁好久不见了,进来看看)
如题 谢谢了...
本人没有写过,,,,希望写过的高手给点提示
分一定给足 最好能够给个事例
------解决方案--------------------微软的click once就不错。你可以查一下相关资料
------解决方案--------------------http://community.csdn.net/Expert/topic/5052/5052832.xml?temp=6.335086E-02
------解决方案--------------------帮你顶一把,顺便学习下
------解决方案--------------------配置文件?爱怎么写就怎么写啊,这还有什么标准吗?
------解决方案--------------------配置文件还不就是xml文件,格式自己定义就行了...
------解决方案--------------------一个例子
Config.xml内容如下:
<?xml version= "1.0 " encoding= "gb2312 "?>
<MyConfig>
<UserName> xingxing </UserName>
<Password> 123456 </Password>
</MyConfig>
=================================================================
//xmlPath()为Xml文件路径 Config.xml
using System;
using System.Text;
using System.IO;
using System.Xml;
public void ReadXml()
{
if (!File.Exists(xmlPath()))
{
XmlTextWriter xmlWriter = new XmlTextWriter(xmlPath(), Encoding.Default);//创建一个xml文档
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement( "MyConfig ");
xmlWriter.WriteStartElement( "UserName ");
xmlWriter.WriteString( " ");
xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement( "Password ");
xmlWriter.WriteString( " ");
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
xmlWriter.Close();
}
if (File.Exists(xmlPath()))
{
XmlDocument XmlDoc = new XmlDocument();
XmlDoc.Load(xmlPath());
XmlElement root = XmlDoc.DocumentElement;
UserName = root.SelectSingleNode( "UserName ").InnerText;
Password = root.SelectSingleNode( "Password ").InnerText;
}
}
public void WriteXml()
{
if (File.Exists(xmlPath()))
{
XmlDocument XmlDoc = new XmlDocument();
XmlDoc.Load(xmlPath());
XmlElement root = XmlDoc.DocumentElement;
root.SelectSingleNode( "UserName ").InnerText = "xingxing ";
root.SelectSingleNode( "Password ").InnerText = "123456 ";
XmlDoc.Save(xmlPath());
}
}