【发布时间】:2014-04-09 12:41:14
【问题描述】:
我正在尝试使用 C# 和 .NET(版本 2.0.. 是的,版本 2.0)创建 XmlDocument。我已使用以下方法设置命名空间属性:
document.DocumentElement.SetAttribute(
"xmlns:soapenv", "http://schemas.xmlsoap.org/soap/envelope");
当我创建一个新的XmlElement 时:
document.createElement("soapenv:Header");
...它在最终 XML 中不包含 soapenv 命名空间。任何想法为什么会发生这种情况?
更多信息:
好的,我会试着澄清一下这个问题。我的代码是:
XmlDocument document = new XmlDocument();
XmlElement element = document.CreateElement("foo:bar");
document.AppendChild(element); Console.WriteLine(document.OuterXml);
输出:
<bar />
但是,我想要的是:
<foo:bar />
【问题讨论】:
标签: c# .net xml namespaces