【发布时间】:2012-10-24 13:54:52
【问题描述】:
我有这个代码:
function setupProject($projectFile) {
[xml]$root = Get-Content $projectFile;
$project = $root.Project;
$beforeBuild = $root.CreateElement("Target", "");
$beforeBuild.SetAttribute("name", "BeforeBuild");
$beforeBuild.RemoveAttribute("xmlns");
$project.AppendChild($beforeBuild);
$root.Save($projectFile);
}
它应该在 XML 文档中添加一个新的<Target name="BeforeBuild" />。
但它也添加了一个我不想要的空 xmlns="" 属性。
(其实是Visual Studio不喜欢这个属性!)
<Target name="BeforeBuild" xmlns="" />
我已经尝试过这段代码:
$beforeBuild.RemoveAttribute("xmlns");
$project.AppendChild($beforeBuild);
$beforeBuild.RemoveAttribute("xmlns");
【问题讨论】:
标签: xml dom powershell appendchild