HtmlAgilityPack给出异常“无法创建多个节点要素". [英] HtmlAgilityPack giving exception "Multiple node elments can't be created."

查看:69
本文介绍了HtmlAgilityPack给出异常“无法创建多个节点要素".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些输入标签,它们是用一些HTML替换的占位符.我正在使用下面的代码来创建html节点,下面是代码片段.但是,由于没有多个节点,这会产生错误,因为无法创建多个节点元素".

I have some input tags that are placeholders that I am replacing with some HTML. I am using below code to create html node below is the code snippet. But it is giving error as "Multiple node elements can't be created" when there are no multiple nodes.

string tempString = "<p style="margin-left:0px;margin-right:0px;text-indent:0px;text-align:justify;">(c)<span style='display: inline-block; width: 30px; min-width: 30px;'>&nbsp;</span><span class='noCount4'> </span>paragraph <span class="Ellh_">(a)<span class='noCount-44'> </span>&nbsp;of Clause <span class='noCount-48'> </span><span class="Ellj_">25.3<span class='noCount-44'> </span>&nbsp;(<span class='noCount-49'></span> </span><i>Other obligations</i>) as a result of an <span class="El2d_">Obligor </span>failing to comply with its obligations under Clause <span class="Ellm_">24.22<span class='noCount-44'> </span>&nbsp;(<span class='noCount-50'></span> </span><i><span class="El2e_">Financial Indebtedness</i></span>);<span class='noCount-1'> </span></span></p>"

HtmlNode tempNode = HtmlNode.CreateNode(tempString);

但是HtmlNode.CreateNode(tempString)给出错误无法创建多个节点元素".

But HtmlNode.CreateNode(tempString) is giving error "Multiple node elements can't be created".

有人可以建议我这是怎么回事.

can any one suggest me what is going wrong here.

推荐答案

无法创建多个节点元素"是正确的,但这可能会导致误导. HtmlNode.CreateNode()仅支持单节点HTML,即只能有一个外部容器节点.

"Multiple node elements can't be created" is correct however this is can be miss-leading. HtmlNode.CreateNode() only supports single node HTML, that is can only have one external container node.

更改此...

<p>
    blah blah...
</p> 
<span>
    More stuff... 
</span>

进入这个...

<div>
   <p>
      blah blah...
   </p>
   <span>
      More stuff...
   </span>
</div>

这篇关于HtmlAgilityPack给出异常“无法创建多个节点要素".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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