Html Agility Pack/C#: how to create/replace tags? -
the task simple, couldn't find answer.
removing tags (nodes) easy node.remove()... how replace them?
there's replacechild() method, requires create new tag. how set contents of tag? innerhtml , outerhtml read properties.
see code snippet:
public string replacetextboxbylabel(string htmlcontent) { htmldocument doc = new htmldocument(); doc.loadhtml(htmlcontent); foreach(htmlnode tb in doc.documentnode.selectnodes("//input[@type='text']")) { string value = tb.attributes.contains("value") ? tb.attributes["value"].value : " "; htmlnode lbl = doc.createelement("span"); lbl.innerhtml = value; tb.parentnode.replacechild(lbl, tb); } return doc.documentnode.outerhtml; }
Comments
Post a Comment