I'm trying to create an XmlDocument
using C# and .NET (version 2.0.. yes, version 2.0). I have set the namespace attributes using:
document.DocumentElement.SetAttribute(
"xmlns:soapenv", "http://schemas.xmlsoap.org/soap/envelope");
When I create a new XmlElement
using:
document.createElement("soapenv:Header");
...it doesn't include the soapenv
namespace in the final XML. Any ideas why this happens?
More info:
Okay, I'll try to clarify this problem a bit. My code is:
XmlDocument document = new XmlDocument();
XmlElement element = document.CreateElement("foo:bar");
document.AppendChild(element); Console.WriteLine(document.OuterXml);
That outputs:
<bar />
However, what I want is:
<foo:bar />
See Question&Answers more detail:os