我有现有的 xml 文档。
例如
<Test>
<A />
</Test>
我将此 xml 加载到 XDocument 中。我需要将属性 xmlns 添加到此文档并使用此属性保存。
var xml = new XDocument.Load("c:\\filePath.xml");
当我尝试这个时:
xml.Root.SetAttributeValue("xmlns", "http://namespaceuri");
我遇到了异常:
System.Xml.XmlException: The prefix '' cannot be redefined from 'http://namespaceuri' to within the same start element tag.
谢谢