c# - How to delete an input based on id and value in Html agility pack -
given below html parsed agility pack
<table> <tbody> <tr> <td colspan="1"> <p>name*</p> <p> <input type="text" size="24" title="name" id="name" name="name" /> </p> </td> </tr> <tr> <td colspan="1"> <p>age*</p> <p> <input type="text" size="24" title="age" id="age" name="age" /> </p> </td> </tr> <tr> <td colspan="1"> <p>date*</p> <p> <input type="text" size="24" title="date" id="date" name="date" /> </p> </td> </tr> <tr> <td colspan="1"> </td> </tr> <tr> <td> <span> <input type="text" id="txtcaptcha" readonly="readonly" />  <input type="button" onclick="rendercaptcha()" value="refresh" /><br />  <input type="text" style="width: 140px;" id="txtverification" /></span>   </td> </tr> <tr> <td colspan="1"> <p id="radetempnode">  <input type="submit" class="brochur" value="submit" id="complaintformsubmit" />   <input type="button" class="brochur" value="reset" id="complaintformreset" />   </p> </td> </tr> </tbody> </table>
i want remove inputs id complaintformreset,complaintformsubmit,txtverification , 1 value refresh.
is there way this?
given below code have tried
var document = new htmldocument(); document.loadhtml(html); var nodes = new queue<htmlnode>(document.documentnode.descendants()); while (nodes.count > 0) { var node = nodes.dequeue(); //if (node.name != "strong" && node.name != "em" && node.name != "u" && node.name != "#text") if(node.id!="") { var parentnode = node.parentnode; if (node.attributes["id"] != null && (string.compare(node.attributes["id"].value, "txtverification", stringcomparison.invariantculture) == 0 || string.compare(node.attributes["id"].value, "complaintformsubmit", stringcomparison.invariantculture) == 0 || string.compare(node.attributes["id"].value, "complaintformreset", stringcomparison.invariantculture) == 0)) { if (null != node.parentnode) { parentnode.removechild(node, true); //nodes.enqueue(node); } //node.removeall(); } } } string dd =document.documentnode.innerhtml;// final htm still contains node had tried remove
is there wrong me?
Comments
Post a Comment