I don't think this is what you are looking for exactly or the best way to do things, but I thought I'd add it here in case it leads you to a better solution:
private void TestDocument()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<animal><dog>Doggo</dog><cat>Catsy</cat></animal>");
AddAttribute(doc.DocumentElement, "xmlns", "");
StringWriter sw = new StringWriter();
XmlTextWriter xtw = new XmlTextWriter(sw);
doc.WriteTo(xtw);
MessageBox.Show(sw.ToString());
}
private void AddAttribute(XmlNode node, string attribute, string value)
{
if (node.NodeType == XmlNodeType.Element)
{
node.Attributes.Append(node.OwnerDocument.CreateAttribute(attribute));
node.Attributes[attribute].Value = value;
foreach (XmlNode subnode in node.ChildNodes)
{
AddAttribute(subnode, attribute, value);
}
}
}