title: Creating a XML file from a database with a model C#
body: <p>So I need to create a method that makes an XML file from a database, I have already written the stored procedures that get the information from a database for the XML now I only need to write the part where I convert my database to a XML file using the properties of another class that I have written as nodes.</p>
  
  <pre><code>public string CreateXML(Object YourClassObject){    
        XmlDocument xmlDoc =new XmlDocument();   //Represents an XML document, 
                  // Initializes a new instance of the XmlDocument class.          
        XmlSerializer xmlSerializer = new XmlSerializer(YourClassObject.GetType());            
      // Creates a stream whose backing store is memory. 
         using (MemoryStream xmlStream =new MemoryStream())
         { 
          xmlSerializer.Serialize(xmlStream, YourClassObject);
          xmlStream.Position = 0;
          //Loads the XML document from the specified string.
          xmlDoc.Load(xmlStream); 
          return xmlDoc.InnerXml;
         }
  }
  </code></pre>
  
  <p>This is some code I found online I think I can use for serializing my model, but i'm accessing the database over an event that I created (I'll provide the code tomorrow when I get to work). Anyway I'm accesing the database in the event like the following e.DataTable. Any ideas anybody?</p>
  
  <p>My model looks like the following:</p>
  
  <pre><code>public class DataModel
  {
  string Sifra {get; set;}
  public string Naziv {get; set;}
  public string JM {get; set;}
  public int Kolicina {get; set;}
  public float Cena_x0020_vp {get; set;}
  public float Cena_x0020_mp {get; set;}
  public float Cena_x0020_bod {get; set;}
  public string Slika {get; set;}
  public string Grupa {get; set;}
  }
  </code></pre>
  
  <p>This is a sample of how my generated XML should look like.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;dataroot xmlns:od="urn:schemas-microsoft-com:officedata" generated="2019-04-17T19:13:54"&gt;
  
  &lt;row&gt;
  
  &lt;Sifra&gt;ADA110-100&lt;/Sifra&gt;
  
  &lt;Naziv_x0020_artikla&gt;Adapter 220/110VAC 100W&lt;/Naziv_x0020_artikla&gt;
  
  &lt;JM&gt;kom&lt;/JM&gt;
  
  &lt;Kolicina&gt;1&lt;/Kolicina&gt;
  
  &lt;Cena_x0020_vp&gt;2683.33&lt;/Cena_x0020_vp&gt;
  
  &lt;Cena_x0020_mp&gt;3220&lt;/Cena_x0020_mp&gt;
  
  &lt;Cena_x0020_bod&gt;28&lt;/Cena_x0020_bod&gt;
  
  &lt;Slika1&gt; ada110v.jpg&lt;/Slika1&gt;
  
  &lt;Grupa&gt;Adateri 110V AC&lt;/Grupa&gt;
  
  &lt;/row&gt;
  </code></pre>