与HtmlAgilityPack在解析时删除空格和换行 [英] Remove whitespaces and newlines when parsing with HtmlAgilityPack

查看:841
本文介绍了与HtmlAgilityPack在解析时删除空格和换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图以下列方式的HtmlAgilityPack解析的HTML

I tried to parse HTML with the HtmlAgilityPack in the following way:

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

不幸的是,xhtmlString包含空格不必要的和换行字符,因此HTMLDOC的_text现在看起来是这样的:

Unfortunately the xhtmlString contains unnecessary whitespaces and newline characters, so the _text of htmlDoc now looks like this:

< HTML xmlns=\\\"http://www.w3.org/1999/xhtml\\\">\
\\t<head></head>\
\\t<body>\
\
<p>Alle Auktionen&LT; BR /&GT;&LT; / P&GT; \\ n \\ n \\ T&LT; / BODY&GT; \\ n&LT; / HTML&GT;

这与身体的子元素时是我的问题。

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

什么是删除这些不必要的字符的最简单方法?

What is the easiest way to remove these unnecessary characters?

是否HtmlAgilityPack提供某种功能,用于从换行和制表清理HTML?

Does the HtmlAgilityPack offer some kind of function for cleaning up HTML from newlines and tabs?

推荐答案

这是文件的缩进和没有必要的空格和换行字符。
结果
我不能看到如何,这可能是一个问题,但你不能只是替换特殊characteres如\\ t的\\ n?
搜索结果
做一个快速的搜索,我发现这个的Html敏捷性包:让code看起来整齐
结果
也许设立一些属性设置为false会有所帮助。

This is the document indentation and not unnecessary whitespaces and newline characters.
I cant see how this could be a problem but cant you just replace the special characteres such as "\t", "\n" ?

Doing a fast search i found this Html Agility Pack: make code look neat
Maybe setting up some properties to false can be helpful

这篇关于与HtmlAgilityPack在解析时删除空格和换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆