简体   繁体   English

使用xmlSerializer.Deserialize读取字符串

[英]using xmlSerializer.Deserialize to read a string

I'm creating a program to read to SVN to see what files have changed in each commit. 我正在创建一个程序以读取SVN,以查看每次提交中更改了哪些文件。

I've got the program getting the data and storing it into a string. 我有程序获取数据并将其存储到字符串中。 What I now need to do is to analyze the data. 我现在需要做的是分析数据。 I do not want to create an xml file as I've done it before. 我不想像以前那样创建xml文件。 I'm unsure how to analyze the data this is may code where it's reading an xml file. 我不确定如何分析读取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);
}

You may use a simple StringReader for this: 您可以为此使用一个简单的StringReader

var serializer = new XmlSerializer(typeof(log));
log logInstance;

using (TextReader reader = new StringReader(myXmlString))
{
    logInstance = serializer.Deserialize(reader);
}

Which reads from a string instead of a file. string而不是文件中读取。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM