开发者

Using HTMLAgilityPack to parse an HTML string not from a URL

开发者 https://www.devze.com 2023-03-25 06:01 出处:网络
I am trying to take a string that I have marked up through vb.net code and cross-check it with the text file it came from originally. This is for proofreading the html output.

I am trying to take a string that I have marked up through vb.net code and cross-check it with the text file it came from originally. This is for proofreading the html output.

To do this, I need to parse an HTML snippet that does not come from a URL.

The examples of HTMLAgilityPack I have seen get their input from a URL. Is there a way to parse a string of marked-up text that does not include a header or similar parts of开发者_StackOverflow社区 a well-formed webpage?

Thanks


To parse a string containing an HTML snippet rather than a file or URL, you can use the HtmlDocument as @Oded suggested, but instead of using doc.Load(), use doc.LoadHtml().

String HtmlSnippet = "<p>Example <strong>Html</strong> snippet</p>";
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(HtmlSnippet);


Instead of the WebDocument use HtmlDocument:

HtmlDocument doc = new HtmlDocument();
doc.Load("file.htm");

It is the first thing on the HAP examples page.

0

精彩评论

暂无评论...
验证码 换一张
取 消