0
我有一个XmlWriter,它已经有一个xmlns
属性集的根元素。用XmlWriter命名空间编写XElement?
我现在有一个XElement(有很多子元素),没有指定名称空间。
如果我只是做:
xElement.WriteTo(writer);
我结束与一个无效的xml:
<MyRootElement xmlns="SomeNameSpace">
<!-- Some elements of this namespace -->
<MyXElementType xmlns="">
<!-- A lot of other Element in the same namespace -->
</MyXelementType>
<!-- Some elements of this namespace -->
</MyRootElement>
,因为它禁止指定一个空的命名空间。这是有问题的,因为我需要在XSD之后进行验证。
我可以做这样结束:
<MyXElementType><!-- HERE, no xmlns !!! -->
<!-- A lot of other Element in the same namespace -->
</MyXelementType>
<!-- Some elements of this namespace -->
</MyRootElement>
好吧,其实我在另一篇文章阅读,它可能是空的,但是这仅仅是默认行为:
或者事后,而不是我们之后可以设置的东西。也许我误解了 – J4N