XDocument default namespace
Posted
by Anthony Faull
on Stack Overflow
See other posts from Stack Overflow
or by Anthony Faull
Published on 2010-05-20T14:02:09Z
Indexed on
2010/05/20
14:40 UTC
Read the original article
Hit count: 265
c#
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?
© Stack Overflow or respective owner