TXmlDocument控件使用问题
procedure TForm1.Button3Click(Sender: TObject);
var
dwI, dwJ: Integer;
OutXMLDoc: TXMLDocument;
Root, Parent_Node, Child_Node, ANode: IXMLNode;
begin
OutXMLDoc := TXMLDocument.Create(Self);
OutXMLDoc.Active := True;
OutXMLDoc.Encoding := 'GB2312 ';
Root := OutXMLDoc.AddChild( 'program ');
for dwI := 0 to 2 do
begin
Parent_Node := Root.AddChild( 'gp ');
Parent_Node.Attributes[ 'name '] := 'group ' + IntToStr(dwI);
Parent_Node.Attributes[ 'begin '] := '000000 ';
Parent_Node.Attributes[ 'end '] := '070000 ';
Parent_Node.Attributes[ 'keep '] := '180 ';
Parent_Node.Attributes[ 'desc '] := '联想 ' + IntToStr(dwI);
for dwJ := 1 to 4 do
begin
Child_Node := Parent_Node.AddChild( 'pi ');
Child_Node.Attributes[ 'keep '] := IntToStr(60 * dwJ);
Child_Node.Attributes[ 'video '] := IntToStr(dwI) + '0 ' + IntToStr(dwJ) + '.jpg ';
Child_Node.Attributes[ 'etype '] := '1 ';
Child_Node.Attributes[ 'audio '] := '101.wav ';
Child_Node.Attributes[ 'atype '] := '0 ';
Child_Node.Attributes[ 'akeep '] := '10 ';
Child_Node.Attributes[ 'ainterval '] := '20 ';
end;
end;
OutXMLDoc.SaveToFile( 'C:\Output.xml ');
OutXMLDoc.Active := False;
end;
以上代码生成的Output.xml文件可以被浏览器正确识别,但用记事本打开后,发现 <?xml version= "1.0 " encoding= "GB2312 "?> 为第一行,其余全部在第二行。
如何让其分行缩进?
[解决办法]
呵呵
另外,NaitveXML这套第三方控件也相当不错的