XmlWriter
allow you to write the xmlns attribute when you want if the value is the same than the one specified in WriteStartElement
:
void Main()
{
StringWriter stringWriter = new StringWriter();
using(XmlWriter writer = XmlWriter.Create(stringWriter))
{
writer.WriteStartDocument();
writer.WriteStartElement("Return", "http://address/here");
writer.WriteAttributeString("xmlns", "http://address/here");
writer.WriteAttributeString("appName", "Data Return - Collection Tool");
writer.WriteAttributeString("appVer", "1.1.0");
writer.WriteEndElement();
writer.WriteEndDocument();
}
Console.WriteLine(stringWriter.ToString());
}
Output :
<Return xmlns="http://address/here" appName="Data Return - Collection Tool" appVer="1.1.0" />