uses NativeXml; 
 
procedure TForm1.Button1Click(Sender: TObject); 
var 
  xml: TNativeXml; 
  fVal: Double; 
begin 
  fVal := 123.456789; 
 
  xml := TNativeXml.CreateName('List'); 
  xml.XmlFormat := xfReadable; 
 
  //xml.FloatSignificantDigits := ; 
  with xml.Root.NodeNew('item') do begin 
    WriteString('Name', 'AAA'); 
    WriteFloat('Weight', fVal); 
  end; 
 
  xml.FloatSignificantDigits := 5; 
  with xml.Root.NodeNew('item') do begin 
    WriteString('Name', 'BBB'); 
    WriteFloat('Weight', fVal); 
  end; 
 
  xml.FloatSignificantDigits := 1; 
  with xml.Root.NodeNew('item') do begin 
    WriteString('Name', 'CCC'); 
    WriteFloat('Weight', fVal); 
  end; 
 
  xml.FloatSignificantDigits := 9; 
  with xml.Root.NodeNew('item') do begin 
    WriteString('Name', 'DDD'); 
    WriteFloat('Weight', fVal); 
  end; 
 
  ShowMessage(xml.Root[0][1].Value); //123.457 
  ShowMessage(xml.Root[1][1].Value); //123.46 
  ShowMessage(xml.Root[2][1].Value); //100 
  ShowMessage(xml.Root[3][1].Value); //123.456789 
  Memo1.Text := xml.WriteToString; 
  xml.Free; 
end; 
{*************************************** 
<?xml version="1.0" encoding="UTF-8"?> 
<List> 
	<item> 
		<Name>AAA</Name> 
		<Weight>123.457</Weight> 
	</item> 
	<item> 
		<Name>BBB</Name> 
		<Weight>123.46</Weight> 
	</item> 
	<item> 
		<Name>CCC</Name> 
		<Weight>100</Weight> 
	</item> 
	<item> 
		<Name>DDD</Name> 
		<Weight>123.456789</Weight> 
	</item> 
</List> 
*****************************************}

posted on 2011-03-25 21:21  万一  阅读(2978)  评论(0编辑  收藏  举报