Write an XML file:
1 var 2 IXMLDoc : IXMLDocument; 3 XMLNode, xNodeItem: IXMLNode; 4 begin 5 IXMLDoc := NewXMLDocument(); 6 try 7 XMLNode := IXMLDoc.AddChild(‘ConfigInfo‘); 8 9 xNodeItem := XMLNode.AddChild(‘VideoDB‘);10 xNodeItem.Attributes[‘Host‘] := VideoSQLConfig.strAddress;11 xNodeItem.Attributes[‘UserName‘] := VideoSQLConfig.strUserName;12 xNodeItem.Attributes[‘PassWord‘] := VideoSQLConfig.strPassWord;13 xNodeItem.Attributes[‘DBName‘] := VideoSQLConfig.strDBName;14 15 16 IXMLDoc.SaveToFile(strFileName);17 finally18 IXMLDoc := nil;19 end;20 end;
Read XML files:
var IXMLDoc:IXMLDocument; xNodeRoot,xNodeItem:IXMLNode; nIndex: Integer; strNodeName: string;begin if not FileExists(strFileName) then Exit; IXMLDoc := NewXMLDocument(); try IXMLDoc.LoadFromFile(strFileName); xNodeRoot := IXMLDoc.ChildNodes.Nodes[‘ConfigInfo‘]; for nIndex := 0 to xNodeRoot.ChildNodes.Count - 1 do begin xNodeItem := xNodeRoot.ChildNodes[nIndex]; strNodeName := UpperCase(xNodeItem.NodeName); if strNodeName = UpperCase(‘VideoDB‘) then begin VideoSQLConfig.strAddress := xNodeItem.Attributes[‘Host‘]; VideoSQLConfig.strUserName := xNodeItem.Attributes[‘UserName‘]; VideoSQLConfig.strPassWord := xNodeItem.Attributes[‘PassWord‘]; VideoSQLConfig.strDBName := xNodeItem.Attributes[‘DBName‘]; Continue; end; end; finally IXMLDoc:=nil; end
VaR ixmldoc: ixmldocument; xmlnode, xnodeitem: ixmlnode; begin ixmldoc: = newxmldocument (); try xmlnode: = ixmldoc. addchild ('configinfo ');
Xnodeitem: = xmlnode. addchild ('videodb'); xnodeitem. attributes ['host']: = videosqlconfig. straddress; xnodeitem. attributes ['username']: = videosqlconfig. strusername; xnodeitem. attributes ['Password']: = videosqlconfig. strpassword; xnodeitem. attributes ['dbname']: = videosqlconfig. strdbname;
Xnodeitem: = xmlnode. addchild ('videoftp '); xnodeitem. attributes ['host']: = videoftpconfig. strhost; xnodeitem. attributes ['username']: = videoftpconfig. strusername; xnodeitem. attributes ['Password']: = videoftpconfig. strpassword; xnodeitem. attributes ['dir']: = videoftpconfig. strdir; xnodeitem. attributes ['Port']: = inttostr (videoftpconfig. nport); If videoftpconfig. bpassive then xnodeitem. attributes ['passive ']: = '1' else xnodeitem. attributes ['passive ']: = '0'; xnodeitem: = xmlnode. addchild ('recordftp '); xnodeitem. attributes ['host']: = recordftpconfig. strhost; xnodeitem. attributes ['username']: = recordftpconfig. strusername; xnodeitem. attributes ['Password']: = recordftpconfig. strpassword; xnodeitem. attributes ['dir']: = recordftpconfig. strdir; xnodeitem. attributes ['Port']: = inttostr (recordftpconfig. nport); If recordftpconfig. bpassive then xnodeitem. attributes ['passive ']: = '1' else xnodeitem. attributes ['passive ']: = '0 ';
Xnodeitem: = xmlnode. addchild ('videoserver'); xnodeitem. attributes ['serverurl']: = videoserverurl;
Xnodeitem: = xmlnode. addchild ('audioserver'); xnodeitem. attributes ['serverurl']: = audioserverurl;
Xnodeitem: = xmlnode. addchild ('lkj '); xnodeitem. attributes ['lkjtype']: = inttostr (ord (lkjtype ));
Xnodeitem. attributes ['host']: = lkjftpconfig. strhost; xnodeitem. attributes ['username']: = lkjftpconfig. strusername; xnodeitem. attributes ['Password']: = lkjftpconfig. strpassword; xnodeitem. attributes ['dir']: = lkjftpconfig. strdir; If lkjftpconfig. bpassive then xnodeitem. attributes ['passive ']: = '1' else xnodeitem. attributes ['passive ']: = '0'; xnodeitem. attributes ['sharepath']: = lkjsharepath;
Xnodeitem: = xmlnode. addchild ('lkjsql'); xnodeitem. attributes ['host']: = lkjsqlconfig. straddress; xnodeitem. attributes ['username']: = lkjsqlconfig. strusername; xnodeitem. attributes ['Password']: = lkjsqlconfig. strpassword; xnodeitem. attributes ['dbname']: = lkjsqlconfig. strdbname;
Xnodeitem: = xmlnode. addchild ('lkjoracle '); xnodeitem. attributes ['svrname']: = lkjoracleconfig. svrname; xnodeitem. attributes ['user']: = lkjoracleconfig. user; xnodeitem. attributes ['pwd']: = lkjoracleconfig. PWD; ixmldoc. savetofile (strfilename); finally ixmldoc: = nil; end;
XML file read/write example