title: Generate an XML file in Delphi 10.1 and perform basic XML operations?
body: <p>I wanted to create an XML file in Delphi 10.1 using following format</p>
  
  <pre><code>&lt;EmployeeDB&gt;
  &lt;Employees&gt;
  &lt;Employee e.id="1"&gt;
    &lt;eName&gt;value from Edit Box edtName&lt;/eName&gt;
  &lt;ePlace&gt;value from Edit Box edtPlace&lt;/ePlace&gt;
  &lt;/Employee &gt;
  &lt;Employee e.id="2"&gt;
    &lt;eName&gt;value from Edit Box edtName&lt;/eName&gt;
  &lt;ePlace&gt;value from Edit Box edtPlace&lt;/ePlace&gt;
  &lt;/Employee &gt;
  &lt;Employee  e.id="3"&gt;
    &lt;eName&gt;value from Edit Box edtName&lt;/eName&gt;
  &lt;ePlace&gt;value from Edit Box edtPlace&lt;/ePlace&gt;
  &lt;/Employee &gt;
  &lt;/Employees&gt;
  &lt;/EmployeeDB&gt;
  </code></pre>
  
  <p>I wanted to take data from a registration form and when the OK button is clicked it should add the data from Edit Boxes, RadioButtons etc.. to XML file.</p>
  
  <p>I am new to Delphi Programming, help me sorting this out.</p>
  
  <p>I tried writing the code in this way:</p>
  
  <pre><code>unit XMLTrail;
  
  interface
  
  uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
    System.Classes, Vcl.Graphics, XMLIntf, XMLDoc, ComObj, xmldom,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
  
  type
    Tfrm_XMLTrail = class(TForm)
      edt_eID: TEdit;
      edtName: TEdit;
      edtPlace: TEdit;
      Memo1: TMemo;
      btnAdd: TButton;
      procedure btn_AddClick(Sender: TObject);
      procedure FormCreate(Sender: TObject);
    private
      { Private declarations }
      procedure LoadXML;
      procedure SaveXML;
    public
      { Public declarations }
      XMLDoc1: TXmlDocument;
  
      iNode, Root1, Root2, Child_Attrib_Name, Child_Attrib_Place: IXmlNode;
      function GetEmployeeDBNode(XMLDoc: TXmlDocument): IXmlNode;
      function GetEmployeesNode(EmployeeDBNode: IXmlNode): IXmlNode;
  
    end;
  
  var
    frm_XMLTrail: Tfrm_XMLTrail;
  
  implementation
  
  {$R *.dfm}
  
  const
    scXmlTemplate = '&lt;EmployeeDB&gt;'#13#10 + '  &lt;Employees&gt;'#13#10 +
      '  &lt;/Employees&gt;'#13#10 + '&lt;/EmployeeDB&gt;';
  
    scXmlFileName =
      'C:\Users\Rajesh\Documents\Embarcadero\Studio\Projects\Samples\XML trail\Win32\Debug\nicexml.xml';
  
  procedure Tfrm_XMLTrail.btn_AddClick(Sender: TObject);
  begin
    XMLDoc1.Active := true;
    iNode := XMLDoc1.DocumentElement;
    Root1 := iNode.ChildNodes.FindNode('Employees');
    Root2 := Root1.AddChild('Employee');
    Root2.Attributes['e.id'] := edt_eID.Text;
    Child_Attrib_Name := Root2.AddChild('eName');
    Child_Attrib_Name.Text := edtName.Text;
    Child_Attrib_Place := Root2.AddChild('ePlace');
    Child_Attrib_Place.Text := edtPlace.Text;
    XMLDoc1.Active := true;
    XMLDoc1.SaveToFile(scXmlFileName);
  
  end;
  
  procedure Tfrm_XMLTrail.FormCreate(Sender: TObject);
  begin
    XMLDoc1 := TXmlDocument.Create(nil);
    if not FileExists(scXmlFileName) then
    begin
      // XMLDoc1 := TXmlDocument.Create(nil);
      XMLDoc1.Active := true;
      XMLDoc1.Options := [doNodeAutoIndent];
      iNode := XMLDoc1.AddChild('UmangEmployeeDB');
      Root1 := iNode.AddChild('Employees');
    end
    else
    begin
      LoadXML;
    end;
  end;
  
  procedure Tfrm_XMLTrail.LoadXML;
  begin
    XMLDoc1.LoadFromFile(scXmlFileName);
    Memo1.Lines.Text := XMLDoc1.XML.Text;
    // SaveXML;
    // Memo1.Lines.LoadFromFile(scXmlFileName);
  
    // XMLDoc1 := TXmlDocument.Create(nil);
    // Assert(Root1 &lt;&gt; Nil);
  end;
  
  procedure Tfrm_XMLTrail.SaveXML;
  begin
    Memo1.Lines.SaveToFile(scXmlFileName);
  end;
  
  end.
  </code></pre>
  
  <p>But it returned the XML file like below:</p>
  
  <pre><code>&lt;EmployeeDB&gt;
      &lt;Employees&gt;
          &lt;Employee e.id="2"&gt;
              &lt;eName&gt;sssss&lt;/eName&gt;
              &lt;ePlace&gt;fgr&lt;/ePlace&gt;
          &lt;/Employee&gt;
          &lt;Employee e.id="2"&gt;
              &lt;eName&gt;sssss&lt;/eName&gt;
              &lt;ePlace&gt;fgr&lt;/ePlace&gt;
          &lt;/Employee&gt;
      &lt;/Employees&gt;
  &lt;/EmployeeDB&gt;
  </code></pre>
  
  <p>The UI of the application is like in this <a href="https://drive.google.com/file/d/0B3W6HsDatTfVbS1rMmxmVUdTNkE/view?usp=sharing" rel="nofollow noreferrer">Image</a>.</p>
  
  <p>When I click on OK button after entering the data, it should write the data to XML file by creating a new <code>&lt;Employee/&gt;</code> node every time I click OK button.</p>