This project has moved and is read-only. For the latest updates, please go here.
2
Vote

DocumentNode.OuterHtml cache not refreshing

description

If I read DocumentNode.OuterHtml, then make changes to the document, those changes aren't reflected in DocumentNode.OuterHtml. I would presume this is a caching issue, much like - http://htmlagilitypack.codeplex.com/workitem/31858

Sample app looks like this:
    class Program
    {
        const string TEST_HTML = "<html><body></body></html>";

        static void Main(string[] args)
        {
            var doc = new HtmlAgilityPack.HtmlDocument();

            Console.WriteLine("*** Cache OuterHtml first ***");
            doc.LoadHtml(TEST_HTML);
            Console.WriteLine(doc.DocumentNode.OuterHtml);
            doc.DocumentNode.SelectSingleNode("//body").InnerHtml = "<p>Hello World</p>";
            Console.WriteLine(doc.DocumentNode.OuterHtml);
            Console.WriteLine();

            Console.WriteLine("*** Don't cache OuterHtml first ***");
            doc.LoadHtml(TEST_HTML);
            doc.DocumentNode.SelectSingleNode("//body").InnerHtml = "<p>Hello World</p>";
            Console.WriteLine(doc.DocumentNode.OuterHtml);
            Console.WriteLine();

            Console.WriteLine("Press any key");
            Console.ReadKey(true);
        }
    }
Output looks like this:
*** Cache OuterHtml first ***
<html><body></body></html>
<html><body></body></html>

*** Don't cache OuterHtml first ***
<html><body><p>Hello World</p></body></html>

I'm targeting .NET 4.0 (Full, not client profile), using HAP v1.4.6.0

comments