c# - ImportNode 创建空的 xmlns 属性

标签 c# .net xml xmldocument

重新升级此代码:

   var tmpNewNode = xdoc.ImportNode(newNode, true);

    if (oldNode.ParentNode != null)
    {
        oldNode.ParentNode.ReplaceChild(tmpNewNode, oldNode);
        return true;
    }

tmpNewNode 是用空的 xmlns 属性 (xmlns="") 创建的。有什么建议可以避免吗?

10倍

最佳答案

这里可能发生的情况是,newNode 来自未声明 namespace 的文档,但 oldNode 位于具有 namespace 的文档中。在这种情况下,节点将其空白 namespace 移至新文档并显式显示。老实说,如果这只是字符串比较的问题,那么在使用它之前从 XML 字符串中删除所有 xmlns=""实例不会有什么坏处。

关于c# - ImportNode 创建空的 xmlns 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4336367/

相关文章:

python - XPath 使用 lxml 失败

c# - 删除结束元素的空间?

c# - 将控件绑定(bind)到 WPF 中的集合/数组中的单个值

c# - 如何将多线程与 "for"或 "foreach"循环一起使用?

xml - TFS 2013 : "The Project Process Settings must be configured for this feature to be used" running witadmin

c# - 是否可以在 asp.net 中更改/限制 dynamicfilter 的值

c# - ReSharper 错误?不正确的 "expression is always true"

c# - C#:程序正在做一些后台处理时的 “not responding”窗口

c# - 使用 C#.net (Microsoft.Office.Interop.Excel) 在 Excel 中删除折线图中的网格线

c# - 在 C# 下,在 32 位处理器上使用 Int64 是危险的