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();
,但我得到:
The prefix '' cannot be redefined from '' to 'http://example.com' within the same start element tag.
我也试过用(根据一个答案,我发现):
XAttribute(XNamespace.Xmlns,...
但得到了一个错误,以及。
注意:我不想在文档中有多个xmlns。
也许这个工作适合你:http://stackoverflow.com/a/2874572/1373170 – 2013-02-12 20:07:56