I am modifying a HTML file using the HTML Agility Pack.
Here is an example on a HTML file containing tables:
Dim document As New HtmlDocument
Dim tables As Array
document.Load(path_html)
Dim div1 As HtmlNode = HtmlNode.CreateNode("<div></div>")
Dim div2 As HtmlNode = HtmlNode.CreateNode("<div></div>")
tables = document.DocumentNode.Descendants("table").ToArray()
For Each tr As HtmlNode In tables.Descendants("tr").ToArray
tr.AppendChild(div1)
tr.AppendChild(div2)
Next
document.save(path_html)
And here is the result in the HTML file:
<div></div><div></div>
What I would like is:
<div></div>
<div></div>
I think this should be implemented by default as it makes my HTML file unclear.
I saw this question (which is my exact issue) here but the answer is not working for me (maybe because of VB.NET and the answer is C#).
Can anyone help?
newLineNode
? This would beDim newLineNode As HtmlNode = HtmlNode.CreateNode("\r\n")
. Then you would use liketr.AppendChild(div1)
...tr.AppendChild(newLineNode)
...tr.AppendChild(div2)
tables.Descendants("tr").ToArray
throws up a compile error for me. Maybe it's this that's the problem? Can you provide your initial HTML within the question or a least a sample of?