I want to generate an XML of the following format using XmlWriter class in C# -:

<?xml version="1.0" ?> <root> <data> <entry Attrib1="" Attrib2="91.3467" Attrib3="95.3052" Attrib4="6.4722" /> <entry Attrib1="" Attrib2="91.3467" Attrib3="95.3052" Attrib4="6.4722" /> </data> </root>

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

var xmlWriter = XmlWriter.Create(filename); xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("data"); xmlWriter.WriteStartElement("entry"); xmlWriter.WriteAttributeString("attrib1", "value1"); xmlWriter.WriteAttributeString("attrib2", "value2"); xmlWriter.Close();

also, the name of the attributes can included illegal XML characters and that's why I read up on XMLWriter 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 XML using XmlWriter . In short a row of the resulting XML is something like this