【发布时间】:2016-06-21 03:38:13
【问题描述】:
我有一个小问题,我认为这是不费吹灰之力的......但是唉......
我有一些 xml,我想做的就是使用 c# 将 xml:space="preserve" 添加到根元素。
我试过了:
var rootElem = xDoc.Root; // XDocument
rootElem.SetAttributeValue("{xml}space", "preserve");
这样的结果是:
<ProjectDetails xmlns="http://site/ppm" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" p3:space="preserve" xmlns:p3="xml">
我认为这相当于
<ProjectDetails xmlns="http://site/ppm" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:space="preserve">
但由于xml:space是一个特殊属性,我有点怀疑。
所以:
它们是一样的吗?
有没有办法以“干净”的方式将其添加到文档中?
【问题讨论】:
标签: c# linq-to-xml xml-namespaces xattribute