Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
通过在 C# 中通过将节点从源文件克隆到目标文件来从另一个文件创建 xml 文件时,空节点的结构就像<noeud></noeud>变成<noeud/>
<noeud></noeud>
<noeud/>
我试过这个:
if (nodeSource.InnerText.Equals("")) XmlNode nodeDestination = NodeSource.CloneNode(false);
有什么方法可以保持相同的结构。
该格式<element/>通常称为自闭合元素。它是 100% 有效的,并且是首选的存储方法。如果您真的关心(为什么?)重写为扩展格式(<element></element>),您可以考虑编写自己的 XmlTextWriter。本文将对您有所帮助。
<element/>
<element></element>
http://blogs.msdn.com/b/nareshjoshi/archive/2009/01/15/how-to-force-non-self-closing-tags-for-empty-nodes-when-using-xslcompiledtransform-class。 aspx