Search code examples
c#xmlclonenode

structure of selfnodes changes when creating an xml file from another


while creating an xml file from another one by cloning nodes from source to target file in c#, the structure of empty nodes like <noeud></noeud> becomes <noeud/>

i've tried this :

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

is there any method to keep the same structure .


Solution

  • The format <element/> is frequently called a self-closing element. It's 100% valid, and the preferred storage method. If you really care (why?) re-writing to expanded format (<element></element>), you can look at writing your own XmlTextWriter. This article will be helpful for you.

    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