HtmlAgilityPack을 사용하여 외부 HTML을 업데이트하려고합니다. 이 속성은 읽기 전용으로 표시됩니다. 내 질문은 어떻게 외부 HTML을 업데이 트하는 것입니다? 참고 : 나는 내부 html뿐만 아니라 외부 html을 업데이트 할 필요가있다. 다음은 코드입니다.
// Check if there is a nested table
HtmlAgilityPack.HtmlNode nestedtable = tr.SelectSingleNode(".//table");
if (nestedtable != null)
{
// Save Inner/Outer Html and update Outer Html
string strInnerHtml = nestedtable.InnerHtml;
string strOuterHtml = nestedtable.OuterHtml;
string strNewOuterHtml = "<table><tr><td><table><tr><td>inner1update</td><td>inner2update</td></tr></table></td></tr></table>";
// Now update source HtmlDocument
nestedtable.OuterHtml = strNewOuterHtml;
// ^^^ Error line: Property or indexer
//HtmlAgilityPack.HtmlNode.OuterHtml' cannot be assigned to -- it is read only
}
부모에 ReplaceChild
를 사용할 수 있습니다. 구문은 다음과 같습니다.
var newNode = HtmlNode.CreateNode(strNewOuterHtml);
nestedtable.ParentNode.ReplaceChild(newNode, nestedtable);