Здравствуйте!
хочу распарсить Текст в html-документе. А именно, взать по кусочкам все текстовые блоки, применить к ним преобразование, сложить обратно в HTML-элементы и вернуть отформатированный HTML-документ
Прохожу по тегам...
using System;
using mshtml;
namespace tumen.framework.content.Typo
{
public class Typo
{
private string _htmlText;
IHTMLDocument2 _htmlDoc;
HTMLDocumentClass _htmldocClass;
public Typo(string htmlText)
{
_htmlText = htmlText;
_htmldocClass = new HTMLDocumentClass();
_htmlDoc = _htmldocClass as IHTMLDocument2;
_htmlDoc.write(htmlText);
}
public string goToBody()
{
string result = "";
IHTMLElementCollection elementColection = (IHTMLElementCollection)_htmlDoc.all.tags("body");
if (null == elementColection)
return result;
if (0 == elementColection.length)
return result;
return goToElement((IHTMLElement)elementColection.item(null, 0));
}
protected string goToElement(IHTMLElement element)
{
string result = "";
IHTMLElementCollection children = (IHTMLElementCollection)element.children;
if (children.length > 0)
{
foreach (IHTMLElement child in children)
result += "[" + " " + child.tagName +"]" + goToElement( child );
}
else
result += element.outerText;
return result;
}
}
}
тут же выясняется, что такой способ выдергивает не весь текст. Например, для документа
<p>111<b>222</b>333</b>444</p>
алгоритм найдет только 222 333
Подскажите, как можно достучаться до 111 и 444. И как после преобразования их положить на место?...
Заранее спасибо!
данное сообщение получено с www.gotdotnet.ru
ссылка на оригинальное сообщение