XDocument default namespace
- by Anthony Faull
How can I set the default namespace of an existing XDocument (so I can deserialize it with DataContractSerializer). I tried the following:
var doc = XDocument.Parse("<widget/>");
var attrib = new XAttribute("xmlns",
"http://schemas.datacontract.org/2004/07/Widgets");
doc.Root.Add(attrib);
The exception I get is is The prefix '' cannot be redefined from '' to 'http://schemas.datacontract.org/2004/07/Widgets' within the same start element tag.
Any ideas?