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

html-agility-pack

Question

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.

Popular Answer

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



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why