I have an XML file with the below formatting:
I'm trying to create the exact same file, but with different content.
I tried several options but I simply can't write before the XML header to keep the formatting of the file.

Can anyone help? 

```
<MemoQResource ResourceType="NonTrans" Version="1.0">
 <Resource>
  <Guid>8380bf45-86cc-4c18-8ce3-11d69746d630</Guid>
  <FileName>do.txt</FileName>
  <Name>do</Name>
  <Description />
 </Resource>
</MemoQResource>
<?xml version="1.0" encoding="utf-8"?>
 <nonTrans version="1.0">
 <nonTransRule>123456</nonTransRule>
 <nonTransRule>123456</nonTransRule>
 <nonTransRule>123456</nonTransRule>
 <nonTransRule>123456</nonTransRule>
</nonTrans>

```

This is the latest, not working code:

```
private bool ConvertFile(string infile, string outfile)
{
    Guid g = Guid.NewGuid();

    XmlTextWriter writer0 = new XmlTextWriter(outfile, Encoding.UTF8);
    writer0.Formatting = Formatting.Indented;
    writer0.WriteStartElement("MemoQResource");
    writer0.WriteAttributeString("ResourceType", "NonTrans");
    writer0.WriteAttributeString("Version", "1.0");
    writer0.WriteStartElement("Resource");
    writer0.WriteElementString("Guid", Convert.ToString(g));
    writer0.WriteElementString("FileName", filename);
    writer0.WriteElementString("Name", name);
    writer0.WriteElementString("Description", description);
    writer0.WriteEndElement();
    writer0.WriteEndElement();

    writer0.Close();

    XmlWriterSettings settings = new XmlWriterSettings();
    settings.Indent = true;
    settings.IndentChars = "\t";

    XmlWriter writer = XmlWriter.Create(outfile, settings);
    writer.WriteStartDocument();
    writer.WriteStartElement("nonTrans");
    writer.WriteAttributeString("Version", "1.0");

    string[] words = txtBox_source.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
    foreach (string word in words)
    {
        writer.WriteElementString("nonTransRule", word);
    }

    writer.WriteEndElement();
    writer.Close();

    return false;
}

```