Error: “The node to be inserted is from a different document context”

前端 未结 1 1032
别跟我提以往
别跟我提以往 2020-11-30 00:44

When I am calling XmlNode.AppendChild(), I get this error:

The node to be inserted is from a different document context.

相关标签:
1条回答
  • 2020-11-30 01:29

    You need to import the node into the document before appending it:

    XmlNode oNode = moDoc.CreateNode(sNodeType, sName, sNamespaceURI);
    
    //necessary for crossing XmlDocument contexts
    XmlNode importNode = oParent.OwnerDocument.ImportNode(oNode, true);
    
    oParent.AppendChild(importNode);
    return oNode;
    
    0 讨论(0)
提交回复
热议问题