XML Visual C++ .NET

#include "stdafx.h"
#using 
using namespace System;
using namespace System::Xml;
void main()
{
    XmlWriter ^writer;
    try
    {
        XmlWriterSettings ^settings = gcnew XmlWriterSettings();
        settings->Indent = true;
        settings->IndentChars = ("   ");
        settings->NewLineOnAttributes = true;
        writer = XmlWriter::Create("G.xml", settings);
        writer->WriteStartDocument();
        writer->WriteStartElement("M");
        writer->WriteComment("P");
        writer->WriteStartElement("M");
        writer->WriteStartElement("N");
        writer->WriteString("G");
        writer->WriteEndElement();
        writer->WriteStartElement("H");
        writer->WriteAttributeString("D", "1d8");
        writer->WriteAttributeString("D1", "4");
        writer->WriteEndElement();
        writer->WriteEndDocument();
        writer->Flush();
    }
    catch (Exception ^e)
    {
        Console::WriteLine("XML Writer Aborted -- {0}", e->Message);
    }
    finally
    {
        if (writer->WriteState != WriteState::Closed)
        {
            writer->Close();
        }
    }
}