Created
October 6, 2018 16:52
-
-
Save JonathanMagnan/118d4dd3f8fbf12926947603da392fb4 to your computer and use it in GitHub Desktop.
HAP - Load (From File)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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