Comment spécifier un xmlns pour XDocument?

J'ai essayé:

textBox1.Text = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"),
    new XElement("root1", new XAttribute( "xmlns", @"http://example.com"), new XElement("a", "b"))
).ToString();

Mais j'obtiens:

The prefix '' cannot be redefined from '' to 'http://example.com' within the same start element tag.

J'ai aussi essayé de substitution (selon une réponse que j'ai trouvé) :

XAttribute(XNamespace.Xmlns,...

Mais a eu une erreur.

Note: je ne cherche pas à avoir plus d'un xmlns dans le document.

Peut-être que ce travail pour vous: stackoverflow.com/a/2874572/1373170

OriginalL'auteur ispiro | 2013-02-12