【问题标题】:structure of selfnodes changes when creating an xml file from another从另一个创建 xml 文件时,selfnodes 的结构发生变化
【发布时间】:2017-04-21 23:36:52
【问题描述】:

在c#中通过将节点从源文件克隆到目标文件从另一个文件创建xml文件时,<noeud></noeud>等空节点的结构变为<noeud/>

我试过这个:

 if (nodeSource.InnerText.Equals(""))
     XmlNode nodeDestination = NodeSource.CloneNode(false);

有什么方法可以保持相同的结构吗?

【问题讨论】:

    标签: c# xml clonenode


    【解决方案1】:

    <element/> 格式经常被称为自闭合元素。它是 100% 有效的,并且是首选的存储方法。如果您真的关心(为什么?)重写为扩展格式 (<element></element>),您可以考虑编写自己的 XmlTextWriter。本文将对您有所帮助。

    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

    【讨论】:

    • Okey @WilliamWalseth 我会试试的,非常感谢:)
    猜你喜欢
    • 2023-01-12
    • 1970-01-01
    • 1970-01-01
    • 2021-12-25
    • 1970-01-01
    • 1970-01-01
    • 2010-12-20
    • 2022-10-20
    • 1970-01-01
    相关资源
    最近更新 更多