Remove spaces and newlines when parsing with HtmlAgilityPack

I tried to parse HTML using HtmlAgilityPack as follows:

HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(xhtmlString); 

Unfortunately, xhtmlString contains unnecessary spaces and newlines, so _text htmlDoc now looks like this:

<html xmlns=\"http://www.w3.org/1999/xhtml\">\n\t<head></head>\n\t<body>\n\n<p>Alle Auktionen<br /></p>\n\n\t</body>\n</html>

This is a problem for me when working with child elements of the body.

What is the easiest way to remove these extra characters?

Does HtmlAgilityPack offer some kind of function for clearing HTML from new lines and tabs?

+6
source share
1 answer

This is the indentation of the document, not the unnecessary spaces and newlines.
I can't figure out how this could be a problem, but maybe you just replace special characters like "\ t", "\ n"?

Performing a quick search, I found this Html Agility Pack: make the code convenient.
It may be useful to set some properties to false.

+1
source

Source: https://habr.com/ru/post/905195/


All Articles