HtmlAgilityPack preserves white space.

c# html-agility-pack html-parsing

Question

Using Agility Pack for HTML, I'm attempting to highlight a certain text in the HTML string. I may substitute text using<span class="highlight"> nevertheless, the white space surrounding the span tag is gone when I alter the content. For instance, if the words"This text will be highlighted" the end outcome is"This text will be<span class='highlighted'>highlighted</span>" and the white space before the span tag is gone. By doing this, the text before and after the gap is combined with the text itself. I just use that kind of recursive loop:

  1. First child node, please
  2. should the node be#text , thannode.InnerHtml = InnerText.Replace(search_term, span_code)
  3. Step 1 if node has children
  4. after the next sibling, go to step 1.

I then get theInnerHtml of theHtmlDocument a consequence. Before, I attempted to place a gap.<span and then</span> but it eliminated them. A tryHtmlDocument.OptionWriteEmptyNodes = true; It also didn't work. I swapped out all"\n" and "\t" character before constructing with a spaceHtmlDocument and after receiving the html string, it had no effect.

When using HTML Agility Pack, how can I maintain the white space?

1
4
10/28/2011 1:39:07 PM

Accepted Answer

Actually HtmlDocument.OptionWriteEmptyNodes = true; I did what I pleased. I now understood.

3
10/28/2011 1:40:09 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow