Skip to content

Instantly share code, notes, and snippets.

@JonathanMagnan
Created October 6, 2018 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonathanMagnan/118d4dd3f8fbf12926947603da392fb4 to your computer and use it in GitHub Desktop.
Save JonathanMagnan/118d4dd3f8fbf12926947603da392fb4 to your computer and use it in GitHub Desktop.
HAP - Load (From File)
// Description: HAP - Load (From File)
// Website: https://html-agility-pack.net/
// Run: https://dotnetfiddle.net/EsvZyg
// @nuget: HtmlAgilityPack
using System;
using System.Xml;
using HtmlAgilityPack;
public class Program
{
public static void Main()
{
SaveHtmlFile();
#region example
var path = @"test.html";
var doc = new HtmlDocument();
doc.Load(path);
var node = doc.DocumentNode.SelectSingleNode("//body");
Console.WriteLine(node.OuterHtml);
#endregion
}
private static void SaveHtmlFile()
{
var html =
@"<!DOCTYPE html>
<html>
<body>
<h1>This is <b>bold</b> heading</h1>
<p>This is <u>underlined</u> paragraph</p>
<h2>This is <i>italic</i> heading</h2>
</body>
</html> ";
var htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(html);
htmlDoc.Save("test.html");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment