更新文件等。
<?xml version="1.0" encoding="utf-8" ?>
<Update>
<NowVersion>1.0.0.0</NowVersion>
<Time>2008-08-01</Time>
<UpdateFileList>
<File Name="test.dll" Message="修正了××××××××××小bug"></File>
<File Name="test.pdb" Message="MiddleDataTier.dll运行必须文件"></File>
</UpdateFileList>
</Update>
下面是代码:
第一步:获取指定路径的xml字符串序列;
HttpWebRequest myRequest
=
(HttpWebRequest)WebRequest.Create(ClientApplicationInfo.XMLFile);
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
Stream ReceiveStream = myResponse.GetResponseStream();
this .OnServerConnectedSucceed();
LogManager.TraceWrite( " [AutoUpdater.IsServerManifestDownloaded] " , " RESX_MESSAGE_ServerConnSucceed " );
Encoding encode = System.Text.Encoding.GetEncoding( " utf-8 " );
StreamReader sr = new StreamReader(ReceiveStream, encode);
Char[] read = new Char[ 256 ];
string strResult = "" ;
int count = sr.Read(read, 0 , 256 );
while (count > 0 )
{
String str = new String(read, 0, count);
strResult += str;
count = sr.Read(read, 0, 256);
}
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
Stream ReceiveStream = myResponse.GetResponseStream();
this .OnServerConnectedSucceed();
LogManager.TraceWrite( " [AutoUpdater.IsServerManifestDownloaded] " , " RESX_MESSAGE_ServerConnSucceed " );
Encoding encode = System.Text.Encoding.GetEncoding( " utf-8 " );
StreamReader sr = new StreamReader(ReceiveStream, encode);
Char[] read = new Char[ 256 ];
string strResult = "" ;
int count = sr.Read(read, 0 , 256 );
while (count > 0 )
{
String str = new String(read, 0, count);
strResult += str;
count = sr.Read(read, 0, 256);
}
第二步:对该字符串序列进行解析,得到一个xmlDocemet对象,代码如下:(注:上面代码中的字符串序列为strResult)
XmlDocument ServerDoc
=
new
XmlDocument();
ServerDoc.LoadXml(strResult);
string _latestVersion = ServerDoc.SelectSingleNode( @" descendant::NowVersion " ).InnerText;
ServerDoc.LoadXml(strResult);
string _latestVersion = ServerDoc.SelectSingleNode( @" descendant::NowVersion " ).InnerText;
第三步:我们得到了我们想要的值。如版本号,然后我们就可以进行读写了或者相互比较了。
注:个人觉得xml文件在传输数据和保存数据中有很大的优势,尤其是在作为配置文件中作用尤其明显,我们没有必要死缠烂打去读取注册表,
读写ini文件,或者连接数据库,如果能用xml文件解决的话,也许世界会豁然开朗。呵呵,这个只是本人的一些拙见,xml的重要性还是不言自明的吧。
欢迎各位指教。