SoFunction
Updated on 2025-03-08

C# simple way to write to xml files

This article describes the method of simply writing to xml files in C#. Share it for your reference. The specific implementation method is as follows:

static void writeTree(XmlNode xmlElement, int level) {
  String levelDepth = "";
  for(int i=0;i<level;i++) 
  {
   levelDepth += "  ";
  }
  ("\n{0}<{1}",levelDepth,);
  XmlAttributeCollection xmlAttributeCollection = ;
  foreach(XmlAttribute x in xmlAttributeCollection) 
  {
   (" {0}='{1}'",,);
  }
  (">");
  XmlNodeList xmlNodeList = ;
  ++level;
  foreach(XmlNode x in xmlNodeList) 
  {
   if( == ) 
   {
     writeTree((XmlNode)x, level);
   }
   else if( == ) 
   {
     ("\n{0}  {1}",levelDepth,().Trim());
   }
  }
  ("\n{0}</{1}>",levelDepth,);
}

I hope this article will be helpful to everyone's C# programming.