Search code examples
c#xmlxml-serializationscreen-scraping

How can I keep a .XML file in memory, then save the document to disc as a regular XML file?


I'm going to be doing some webscraping and my plan is to have something like this:

public class Searcher
{
    public void Search(string searchTerm)
    {
    }

    private void Search(string term)
    { 
        //Some HTMLAgilityPack Voodoo here
    }

    private void SaveResults()
    {
        //Actually save the results as .XML file.
    }
}

Is there a way I can keep an .XML file with its contents and everything in memory, and then save the document to disc as a regular XML file?


Solution

  • Either the XDocument or XmlDocument classes will allow you to keep XML in memory as XML.