var
  pRoot,cRoot,cRoot1,cRoot2 :IXMLNode;//pRoot根节点,cRoot子节点
  i :Integer;
  XMLDocument1: TXMLDocument;
begin
  try
    XMLDocument1.Active :=True ;
    XMLDocument1.Version := '1.0'; //设置版本
    XMLDocument1.ChildNodes.Clear;
    XMLDocument1.Encoding := 'UTF-8';//'GB2312'; //设置语言
    pRoot := XMLDocument1.AddChild('xml'); //添加的第一个节点是根节点, 现在的 mRoot 是根节点
    cRoot := pRoot.AddChild('sys');//为根节点添加子节点}
    cRoot.Text :='';
    cRoot := pRoot.AddChild('items'); //为根节点添加子节点}
    for i :=1 to 2 do
    begin
      cRoot1 := cRoot.AddChild('item'); //为根节点添加子节点}
      cRoot1 := cRoot1.AddChild('head'); //为根节点添加子节点}
      cRoot2 := cRoot1.AddChild('SiteCode');
      cRoot2.Text := 'JSRM';
      cRoot2 := cRoot1.AddChild('orgCode');
      cRoot2.Text := 'JSRM';
      cRoot2 := cRoot1.AddChild('ProcuctID');
      cRoot2.Text := 'test00'+IntToStr(i);
      cRoot2 := cRoot1.AddChild('MedicineName');
      cRoot2.Text := 'testmedicinename';
      cRoot2 := cRoot1.AddChild('ProductName');
      cRoot2.Text := 'test product name';
      cRoot2 := cRoot1.AddChild('ProductSpec');
      cRoot2.Text := 'test product spec';
      cRoot2 := cRoot1.AddChild('ProductStyle');
      cRoot2.Text := 'test productstyl';
      cRoot2 := cRoot1.AddChild('Manufacturer');
      cRoot2.Text := 'test manufacturer';
      cRoot2 := cRoot1.AddChild('CertificateNo');
      cRoot2.Text := 'test certificateno';
      cRoot2 := cRoot1.AddChild('ProductValue');
      cRoot2.Text := 'test productvalue';
      cRoot2 := cRoot1.AddChild('IsActive');
      cRoot2.Text := 'Y';
      cRoot2 := cRoot1.AddChild('IsQAStop');
      cRoot2.Text := 'N';
      cRoot2 := cRoot1.AddChild('IsStop');
      cRoot2.Text := 'N';
      cRoot2 := cRoot1.AddChild('UOM');
      cRoot2.Text := '盒';
      cRoot2 := cRoot1.AddChild('PriceList');
      cRoot2.Text := '200';
      cRoot2 := cRoot1.AddChild('UPC');
      cRoot2.Text := '12345';
      cRoot2 := cRoot1.AddChild('LPackageQty');
      cRoot2.Text := '100';
      cRoot2 := cRoot1.AddChild('Re');
      cRoot2.Text := '无';
      cRoot2 := cRoot1.AddChild('Timestamp');
      cRoot2.Text := FormatDateTime('YYYY-MM-DD HH:MM:SS',Now);
    end;
    mmo2.Lines :=XMLDocument1.XML;
    XMLDocument1.SaveToFile('99.xml');
    XMLDocument1.Active :=False ;  finally
  end;end;//还有如果解析编码如何处理XMLDELPHI乱码webservices