I have existing xml document.
e.g
<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.
谢谢
Test
和A
元素的命名空间吗? - John Saunders