This document already has a ' DocumentElement ' node

前端 未结 1 938
心在旅途
心在旅途 2020-12-31 01:00

I\'m adding a new node at the end of a file, but I get a write error:

This document already has a \'DocumentElement\' node.

My c

1条回答
  •  一整个雨季
    2020-12-31 01:54

    You should use

    XmlNode refElem = doc.DocumentElement.LastChild;
    

    and

    doc.DocumentElement.InsertAfter(entryElement, refElem);
    

    EDIT

    You may also use

    doc.DocumentElement.AppendChild(entryElement);
    

    In this case refElem is not needed.

    0 讨论(0)
提交回复
热议问题