HtmlAgilityPack giving exception “Multiple node elments can't be created.”

痴心易碎 提交于 2019-12-10 20:55:18

问题


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);

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

can any one suggest me what is going wrong here.


回答1:


"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.

Change this...

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

Into this...

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


来源:https://stackoverflow.com/questions/48428938/htmlagilitypack-giving-exception-multiple-node-elments-cant-be-created

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!