C#Pars html字符串标记文本

时间:2022-09-13 08:05:33

i want to pars a HTML string like:

我想解析一个HTML字符串,如:

<b><a href="/wiki/Schizophrenie" title="Schizophrenie">Schizophrenie</a></b> ist eine schwere psychische Erkrankung. Sie

or

    <h2 class="sectionedit2" id="zu_treffende_massnahmen">zu treffende Maßnahmen</h2>
<div class="level2">
<ul><li class="level1"><div class="li">An- und Abfahrtswege freihalten; Einweisung nachrückender Kräfte, evtl. Einbahnregelung vorsehen</div>

So that all the Text gets some extra font style elements (<font style = "color:red;">..</font>) like:

这样所有的Text都会获得一些额外的字体样式元素( .. ),如:

<b><a href="/wiki/Schizophrenie" title="Schizophrenie"><font style = "color:red;">Schizophrenie</font></a></b><font style = "color:red;"> ist eine schwere psychische Erkrankung. Sie</font>

or

<h2 class="sectionedit2" id="zu_treffende_massnahmen"><font style = "color:red;">zu treffende Maßnahmen</font></h2>
<div class="level2">
<ul>
<li class="level1"><div class="li"><font style = "color:red;"> An- und Abfahrtswege freihalten; Einweisung nachrückender Kräfte, evtl. Einbahnregelung vorsehen</font></div>

Is there an easy way to do it?

有一个简单的方法吗?

1 个解决方案

#1


0  

If you are about to make a html viewer or editor - avalonedit can do that:

如果您要制作html查看器或编辑器 - avalonedit可以这样做:

http://www.codeproject.com/Articles/42490/Using-AvalonEdit-WPF-Text-Editor

It has a syntaxhighlight definition for html already - really a nice control.

它已经有了html的syntaxhighlight定义 - 真的是一个很好的控件。

But if it is the challenge of doing it yourself - you can see how to start here:

但如果这是自己做的挑战 - 你可以看到如何从这里开始:

http://khason.net/blog/richtextbox-syntax-highlighting/

#1


0  

If you are about to make a html viewer or editor - avalonedit can do that:

如果您要制作html查看器或编辑器 - avalonedit可以这样做:

http://www.codeproject.com/Articles/42490/Using-AvalonEdit-WPF-Text-Editor

It has a syntaxhighlight definition for html already - really a nice control.

它已经有了html的syntaxhighlight定义 - 真的是一个很好的控件。

But if it is the challenge of doing it yourself - you can see how to start here:

但如果这是自己做的挑战 - 你可以看到如何从这里开始:

http://khason.net/blog/richtextbox-syntax-highlighting/