puncha

不同XML之间节点的拷贝

Original: http://www.aspcode.net/The-node-to-be-inserted-is-from-a-different-document-context.aspx 

Soon after I recommended my (just published solution) for merging XML files for a person I know he contacted me and said he was getting the error "The node to be inserted is from a different document context ".

After some investigating it turned out he had not copied the solution by using the clipboad function, but rather typing it in - and missed the oh so important oDocFirst.ImportNode call.

I.e he was using code like:

XmlNode oNodeWhereInsert = oDocFirst.SelectSingleNode("/rss/channel"); 
foreach( XmlNode oNode in oDocSecond.SelectNodes("/rss/channel/item")) 
{ 
    oNodeWhereInsert.AppendChild(oNode.Clone()); 
} 
 

instead of
 
XmlNode oNodeWhereInsert = oDocFirst.SelectSingleNode("/rss/channel"); 
foreach( XmlNode oNode in oDocSecond.SelectNodes("/rss/channel/item")) 
{ 
    oNodeWhereInsert.AppendChild(oDocFirst.ImportNode(oNode,true)); 
} 

PunCha注: 在被拷贝的节点来自于其他XmlDocument是,可以使用XmlDocument.ImportNode来导入节点。

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2022-01-14
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
  • 2021-06-15
猜你喜欢
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
  • 2021-12-21
  • 2021-07-25
  • 2022-12-23
  • 2021-10-03
相关资源
相似解决方案