Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 283
gayatri kulkarni Avatar asked Jan 24 '18 18:01

gayatri kulkarni


1 Answers

"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>
like image 145
Russ Ebbing Avatar answered Sep 28 '22 20:09

Russ Ebbing