【发布时间】:2009-10-22 14:55:03
【问题描述】:
我有一个需要在运行时应用命名空间的 XML 文件。我在网上搜索过,大多数示例似乎都建议使用“SetAttributeValue”函数。当我使用下面的代码时,当我尝试“ToString()”并出现以下错误时会引发异常:
The prefix '' cannot be redefined from '' to 'http://schemas.datacontract.org/2004/07/' within the same start element tag.
有什么想法吗?
XDocument data = XDocument.Parse("<Root><Stuff>Test</Stuff></Root>");
string ns = "http://schemas.datacontract.org/2004/07/";
data.Root.SetAttributeValue("xmlns",ns);
SaveFile(data.ToString());
【问题讨论】:
标签: .net xml namespaces