【问题标题】:remove namespace from childnode created element从子节点创建的元素中删除命名空间
【发布时间】:2013-08-22 16:33:42
【问题描述】:

为了操作在我的 VS 项目中使用的 dll,我必须更新 dll 指向的引用。我通过修改 csproh 的 XML 来做到这一点(是的,这有效)。

但是,这一次我想添加一个 SpecificVersion 引用,所以 <SpecificVersion xmlns="">False</SpecificVersion> 但是当您在 Reference 元素下有一个自定义 xml 命名空间时,您不能使用 microsoft build engine 进行构建。如何删除 SpecificVersion 节点内的xmlns=""

<SpecificVersion xmlns="">False</SpecificVersion>

XmlElement SpecificVersionElement = refNode.OwnerDocument.CreateElement("SpecificVersion");
SpecificVersionElement.InnerText = "False";
refNode.AppendChild(SpecificVersionElement);

【问题讨论】:

标签: c# xml


【解决方案1】:

了不起,像往常一样,在我发布一些东西后 30 秒我就明白了。在这种情况下,这是没有意义的。通过指定命名空间,create 元素有效地移除了命名空间。

XmlElement SpecificVersionElement =     refNode.OwnerDocument.CreateElement("SpecificVersion","http://schemas.microsoft.com/developer/msbuild/2003");
SpecificVersionElement.InnerText = "False";
refNode.AppendChild(SpecificVersionElement);

当然,这可能隐藏在 MSDN 文章的某个深处

【讨论】:

  • 不,你没有删除命名空间——你使用的命名空间与该元素的默认命名空间相同,因为它的父元素。这只是命名空间的默认设置,它是 XML 本身的一部分。
猜你喜欢
  • 2022-08-18
  • 2011-01-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-03
相关资源
最近更新 更多