Fraser Munro
Fraser Munro

Reputation: 21

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.

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. I'm unsure how to analyze the data this is may code where it's reading an xml file.

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);
}

Upvotes: 0

Views: 178

Answers (1)

MakePeaceGreatAgain
MakePeaceGreatAgain

Reputation: 37113

You may use a simple StringReader for this:

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.

Upvotes: 1

Related Questions