Marcus25
Marcus25

Reputation: 883

Appending a string to HTML using htmlagiity pack

I am using HtmlAgilityPack in C#. I loaded my html with

htmlDoc.LoadHtml(model.Content);

Now, I am generating a string like so:

"<div> abc</div><div>xyz</div>"

I want to append this string in the above html before saving. How can this be done?

Upvotes: 0

Views: 89

Answers (2)

a1204773
a1204773

Reputation: 7053

As I understood you just want to join 2 strings. HTML is string, so you have 2 strings.

  1. model.Content
  2. string myString = "<div> abc</div><div>xyz</div>"

To join the strings you must simply do:

string myNewHTML = model.Content + myString;

After that do whatever you want with your text

Load it to HtmlDocument

htmlDoc.LoadHtml(myNewHTML);

or save it to file

File.WriteAllText(path,myNewHTML);

Upvotes: 2

Siddharth Kumar
Siddharth Kumar

Reputation: 134

I haven't used the HTMLagility pack but I think you should be able to do this by dumping your HTML into a string (there will be a function that does it, something like DumpHTML maybe. Just go through the documentation of the library), append/concatenate your new html-like string, and again run the LoadHtml function to convert the new string into an HTML object.

Upvotes: 1

Related Questions