we need to replace it with
public string ParseFromRoot(RootItem root)
{
if (root == null || root.Children.Count == 0)
return string.Empty;
var document = new HtmlDocument();
foreach (var item in root.Children)
ParseNode(document, document.DocumentNode, item);
return document.DocumentNode.InnerHtml;
}
private HtmlNode ParseNode(HtmlDocument document, HtmlNode parentNode, ItemBase item)
{
var node = DefineNode(document, item);
parentNode.ChildNodes.Add(node);
if (item.Children.Count == 0)
return node;
foreach (var child in item.Children)
ParseNode(document, node, child);
return node;
}
document.DocumentNode.InnerHtml
试着从代码中手动建立HTML。 代码,建立HTML。
在这种情况下,在准备好的文档中,当我试图访问时,我得到了Null引用 document.DocumentNode.InnerHtml
. 但InnerText反映的是实际的文本,一切都好吗?
万一我document.LoadHtml("")同样的html.InnerText(""),就会出现 "InnerText"。
<p>dsgwegsdrgsrdeg</p>
<p> </p>
<p>just <strong>typihere</strong></p>
<p> </p>
<ol>
<li>some list</li>
<li>another list</li>
</ol>
<p>j</p>
毫无例外地返回真正的html?
parentNode.ChildNodes.Add(node);
尝试从代码中手动构建HTML。代码,构建html: public string ParseFromRoot(RootItem root) { if (root == null