I have an xml file with default namespace specified with and without namespace prefix. When I generate xml output I'm getting all xml elements prefixed. Is there way to get rid of the prefixes since I'm using the default namespace?
class Program
{
static void Main(string[] args)
{
var xml =
"<root xmlns='default-namespace' xmlns:key='default-namespace'>" +
" <node1></node1>" +
" <node2></node2>" +
"</root>";
var document = XDocument.Parse(xml);
var output = document.ToString();
}
}
The output:
<key:root xmlns="default-namespace" xmlns:key="default-namespace">
<key:node1></key:node1>
<key:node2></key:node2>
</key:root>
What I'd expect:
<root xmlns="default-namespace" xmlns:key="default-namespace">
<node1></node1>
<node2></node2>
</root>
Unfortunately I can't remove the duplicated namespace declaration. The actual xml file I'm using is provided by another party and I need to do as less modifications as possible.