writing elements to an XML file in C#

NallRestor

New Member
So I'm attempting to create a large XML file of the form:\[code\]<xml> <element id ="1">1</element> <element id ="2">2</element> <element id ="3">3</element> ... <element id ="100000000">100000000</element></xml>\[/code\]Using C#. I can't seem to find a way to format the element to include the id in the declaration (I am not familiar with XML at all).Does anyone know how I could do this in C#?Here is my attempt:\[code\]using System;using System.Xml;using System.Linq;using System.Text;namespace BigXML{ class Class1 { static void Main(string[] args) { // Create a new file in C:\\ dir XmlTextWriter textWriter = new XmlTextWriter("C:\\Users\\username\\Desktop\\testBigXmFile.xml", null); textWriter.Formatting = Formatting.Indented; textWriter.Indentation = 3; textWriter.IndentChar = ' '; // Opens the document textWriter.WriteStartDocument(true); textWriter.WriteStartElement("xml"); // Write comments for (int i = 0; i < 100000000; i++) { textWriter.WriteElementString("element id =" + '"' + i.ToString() + '"', i.ToString()); } textWriter.WriteEndElement(); textWriter.WriteEndDocument(); textWriter.Close(); } }}\[/code\]Thank you, and have a nice day.
 
Back
Top