title: How do I generate the following Xml using XmlWriter class in C#?
body: <p>I want to generate an XML of the following format using XmlWriter class in C# -:</p>
  
  <pre><code>&lt;?xml version="1.0" ?&gt;
  &lt;root&gt;
   &lt;data&gt;
    &lt;entry Attrib1="" Attrib2="91.3467" Attrib3="95.3052" Attrib4="6.4722" /&gt;
    &lt;entry Attrib1="" Attrib2="91.3467" Attrib3="95.3052" Attrib4="6.4722" /&gt;
   &lt;/data&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>I am very new to XmlWriter class and to C# in general and I have tried writing code for generating the file with the above format, but that attempt was unsuccessful</p>
  
  <pre><code>var xmlWriter = XmlWriter.Create(filename);
      xmlWriter.WriteStartDocument();
      xmlWriter.WriteStartElement("data");
  
      xmlWriter.WriteStartElement("entry");
      xmlWriter.WriteAttributeString("attrib1", "value1");
      xmlWriter.WriteAttributeString("attrib2", "value2");
      xmlWriter.Close();
  </code></pre>
  
  <p>also, the name of the attributes can included illegal XML characters and that's why I read up on <code>XMLWriter</code> because it seems to remove those illegal characters from the names of the attributes for instance a name like "this is attribute 1" should be reduced to something like "this_is_attribute_1" when written to the resulting XML, how do I go about producing such <code>XML</code> using <code>XmlWriter</code>. In short a row of the resulting XML is something like this</p>
  
  <pre><code>&lt;entry P_B_Pe="" P_E_Pe="91.3467" Custom_Price="95.3052" C_Yield="6.4722" Average_Life="" /&gt;
  </code></pre>