[英]using xmlSerializer.Deserialize to read a string
我正在創建一個程序以讀取SVN,以查看每次提交中更改了哪些文件。
我有程序獲取數據並將其存儲到字符串中。 我現在需要做的是分析數據。 我不想像以前那樣創建xml文件。 我不確定如何分析讀取xml文件時可能編碼的數據。
private void Show_Click(object sender, System.EventArgs e)
{
FileStream fileStream = null;
fileStream = new FileStream(Path.Combine(_filePath, @"svn.log"), FileMode.Open, FileAccess.Read, FileShare.Read);
XmlSerializer xmlSerializer = new XmlSerializer(typeof(log));
log logInstance;
lock (xmlSerializer)
{
logInstance = (log)xmlSerializer.Deserialize(fileStream);
}
_dictionary = CreateDictionary(logInstance);
converToText(_dictionary);
}
您可以為此使用一個簡單的StringReader
:
var serializer = new XmlSerializer(typeof(log));
log logInstance;
using (TextReader reader = new StringReader(myXmlString))
{
logInstance = serializer.Deserialize(reader);
}
從string
而不是文件中讀取。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.