How do I remove whitespace in HTML Source with Html Agility Pack and C#
问题 Before posting I tried the solution from this thread: C# - Remove spaces in HTML source in between markups? Here is a snippet of the HTML I'm working with: <p>This is my text</p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p>This is next text</p> I'm using HTML Agility Pack to clean up the HTML: HtmlDocument doc = new HtmlDocument(); doc.Load(htmlLocation); foreach (var item in doc.DocumentNode.Descendants("p").ToList()) { if (item.InnerHtml == " ") { item.Remove(); } } The output