NativeXml Help
Example D: Creating a simple XML file
This example shows how to create a simple XML file with one node under the root that has an attribute and a subnode. We will try to create this XML file:

<?xml version="1.0" encoding="windows-1252"?>
<Root>
  <Customer ID="123456">
    <Name>John Doe</Name>
  </Customer>
</Root>
Here's the code of a procedure that creates this file and saves it in readable format to a filename "C:\test.xml":

procedure CreateXML;
var
  ADoc: TNativeXml;
begin
  // Create new document with a rootnode called "Root"
  ADoc := TNativeXml.CreateName('Root');
  try
    // Add a subnode with name "Customer"
    with ADoc.Root.NodeNew('Customer') do begin
      // Add an attribute to this subnode
      WriteAttributeInteger('ID', 123456);
      // Add subsubnode
      WriteString('Name', 'John Doe');
    end;

    // Save the XML in readable format (so with indents)
    ADoc.XmlFormat := xfReadable;
    // Save results to a file
    ADoc.SaveToFile('c:\test.xml');
  finally
    ADoc.Free;
  end;
end;