title: Generic way of creating XML files in C#
body: <p>I am trying to create a class which saves/reads multiple XML files using LINQ and Genertics. </p>
  
  <p><strong>I am looking for generic way of saving XMl files of multiple type (i.e data in them)</strong></p>
  
  <p>Every XML file will have following format</p>
  
  <pre><code>&lt;ROOT&gt;
       &lt;!-- First Element/First Row --&gt;
       &lt;NODE&gt;
             &lt;COL1&gt;Some value&lt;/COL1&gt;
             .....  
             &lt;COLn&gt;Some value&lt;/COLn&gt;
       &lt;/NODE&gt;
       .........
       &lt;!-- Nth Element = nth row --&gt;
       &lt;NODE&gt;
             &lt;COL1&gt;Some value&lt;/COL1&gt;
             .....  
             &lt;COLn&gt;Some value&lt;/COLn&gt;
       &lt;/NODE&gt;
  &lt;/ROOT&gt;
  </code></pre>
  
  <p>Every file will have a different ROOT, NODE and COLx. The Number of columns and data in them depends on the Multi-Dim array input. This input array also gives the number of NODES tags in xml (elements in array).</p>
  
  <p>A method to save an XML file looks like</p>
  
  <pre><code>public void SaveFirstXmlFile()
  {
      XElement xdoc = new XElement("ThisDocsRoot");
      //Iterate for number of rows(elements of data)            
      for (int nodes= 1; nodes&lt;= NUMBER_OF_NODES; nodes++)
      {
          xdoc.Add(new XElement(row,
                                new XElement("Col 1", "Some Value"),
                                new XElement("Col 2", "Some Value"),
                                new XElement("Col 3", "Some Value")
                       ));
      } 
      xdoc.Save("/Path/To/XML/File");
  }
  </code></pre>
  
  <p>I wanted to tweak this method so that it works for multiple XML files.I don't know if it is correct way of doiung it, but I strated creating CLasses which define the root,node,columns and path for the XML file. and The data comes from Multi-Dim Arrays created by some other classes.</p>
  
  <pre><code>private class AClassforSomeXMLFile
  {
      private readonly String _root;
      private readonly String _row;
      private readonly String[] _columns;
      private readonly String _exportPath;
  
      public UsageData()
      {
  
          _exportPath = string.Format(@"{0}\xyz.xml",Path.GetDirectoryName(Application.ExecutablePath));
  
          _root = "ROOT";
          _row = "NODE";
          _columns = new string[]
              {
                  "COL1","COL2", "COL3","COL4",
              };
      }
  
      public string ROOT {  get { return _root; } }
  
      public string ROW { get { return _row; } }
  
      public string[] COLS  { get { return _columns; }}
  
      public string EPATH { get { return _exportPath; }}
  }
  </code></pre>