码迷,mamicode.com
首页 > 其他好文 > 详细

XML文件读写示例

时间:2018-10-26 10:37:58      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:add   ora   node   file   ftp   video   roo   dir   文件读写   

写XML文件:

 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   finally
18     IXMLDoc := nil;
19   end;
20 end;

读取XML文件:

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文件读写示例

标签:add   ora   node   file   ftp   video   roo   dir   文件读写   

原文地址:https://www.cnblogs.com/tsolarboy/p/9854567.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!