How to Include Records into XML Element C#

Mar 20 at 4:15 PM
Hi...I would like to please you guys to help me creating this xml file...I've tried with this code above but I've got some Errors...Using VS2013, C#

<Report>
<Versao>1</Versao>
<Details>
<Record>
<ID>1</ID>
<Reference>20171</Reference>
</Record>
<Record>
<ID>2</ID>
<Reference>20172</Reference>
</Record>
</Details>
</Report>
   XDocument docHeader = new XDocument( 
             new XElement("Report",
             new XElement("Versao", "1"),
             new XElement("Details", "")
          ));

        for (int i = 0; i < 2; i++)
        {
           var docRecords =

            new XElement("Record", 

                           new XElement("ID", i.ToString()),

                           new XElement("Reference", "2017" + i.ToString() )
            );

    }

        docHeader.Element("Details").Add(docRecords);

        using (var writer = new XmlTextWriter("C:\\Reports\\MyReport.xml", new UTF8Encoding(false)))
        {
            docHeader.Save(writer);
        }