2

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 a well-formed webpage?

Thanks

2 Answers 2

2

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);
Sign up to request clarification or add additional context in comments.

Comments

0

Instead of the WebDocument use HtmlDocument:

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

It is the first thing on the HAP examples page.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.