110,502
社区成员
发帖
与我相关
我的任务
分享
<html>
<form>
<div>
<label>姓名:</label>
<input class="input" name="" type="text" style="width:445px;"></input>
</div>
</form>
</html>
这应该不麻烦。
使用streamReader 读取成文本,然后使用linq to xml 操作。先移除所有,再追加节点。
string html = "<html><form><div><label>姓名:</label><input class=\"input\" name=\"\" type=\"text\" style=\"width:445px;\"></input></div></form></html>";
XElement temp = XElement.Parse(html);
IEnumerable<XElement> divValue = temp.DescendantsAndSelf("div");
divValue.Elements().Remove();
divValue.FirstOrDefault().Add(new XElement("label", "姓名:张三"));
string newHtml = temp.ToString();