public AppendChild ( |
||
newChild | The node to add. May not be null. | |
return |
HtmlAgilityPack.HtmlNode node = htmlDoc.DocumentNode.SelectSingleNode("//span"); HtmlAgilityPack.HtmlNode childNode = htmlDoc.CreateElement("p"); childNode.InnerHtml = "This is a paragraph"; node.AppendChild(childNode);
HtmlAgilityPack.HtmlNode div = htmlDoc.DocumentNode.SelectSingleNode("//div"); HtmlAgilityPack.HtmlNode childDiv = htmlDoc.CreateElement("div"); HtmlAgilityPack.HtmlNode childParagraph = htmlDoc.CreateElement("p"); childParagraph.InnerHtml = "This is a paragraph"; childDiv.AppendChild(childParagraph); div.AppendChild(childDiv);In this example, we select an HTML node 'div' and create a new child node 'div'. We then create another child node 'p' with the text 'This is a paragraph' and append it to the child 'div' node. Finally, we append the child 'div' node to the original 'div' node. Overall, HtmlAgilityPack is a useful C# package library for manipulating HTML documents, and HtmlNode.AppendChild() is just one of many useful methods in the library.
public AppendChild ( |
||
newChild | The node to add. May not be null. | |
return |