ImportNode创建空的xmlns属性 [英] ImportNode creates empty xmlns attribute
问题描述
改编本code:
var tmpNewNode = xdoc.ImportNode(newNode, true);
if (oldNode.ParentNode != null)
{
oldNode.ParentNode.ReplaceChild(tmpNewNode, oldNode);
return true;
}
tmpNewNode是空的xmlns属性(的xmlns =)创建的。任何建议,我怎么能避免呢?
tmpNewNode is created with empty xmlns attribute (xmlns=""). Any suggestion how can I avoid it?
10倍
推荐答案
什么是可能发生在这里的是,newNode来自一个文件,没有命名空间中声明,但oldNode是与命名空间的文档。在这种情况下,该节点将其空白空间到新文档,并明确地显示出来。说实话,如果它是一个字符串比较只是一个问题,它不会伤害只是从XML字符串中删除的xmlns的所有实例=你使用它。
What's probably happening here is that newNode comes from a document with no namespace declared, but oldNode is in a document with a namespace. In this situation, the node takes its blank namespace over to the new document and it shows up explicitly. To be honest, if it's only a problem for a string comparison, it won't hurt to just remove all instances of xmlns="" from the XML string before you work with it.
这篇关于ImportNode创建空的xmlns属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!