node.ReplaceChild()
How do you use the node.ReplaceChild() method to replace </td></tr><tr><td> tag with the <br /> tag when the <tr> t开发者_C百科ag only has 1 <td> tag?
HtmlDocument htmlDoc = new HtmlDocument();
htmlDoc.OptionFixNestedTags = true;
htmlDoc.Load(HttpContext.Current.Server.MapPath("~/myFolder/rpt.html").ToString());
if(htmlDoc.DocumentNode != null)
{
HtmlNode trNode = htmlDoc.DocumentNode.SelectSingleNode("//tr");
if (trNode != null)
{
//check for more than 1 <td> in the same <tr>
bool td = trNode.ToString().StartsWith("</td><td");
if (td == false)
{
trNode.ReplaceChild("</td></tr><tr><td>","<br />");
}
}
}
I don't think you can do that. </tr> is the closing tag for a <tr> node, not a node in itself. You'd need to process the two nodes involved together. Probably replace the first <tr> node with the combination that you're after, and then remove the second.
加载中,请稍侯......
精彩评论