delphi IniFile To XML


本文整理自网络,侵删。

  

uses XMLIntf, XMLDoc, INIFiles;

procedure INI2XML(const pINIFileName: string; const pXML: IXMLNode;

const AsAttributes: Boolean = true);

var

lINIFile: TIniFile;

lSections, lItems: TStringList;

iSections, iItems: integer;

lNode: IXMLNode;

begin

lINIFile := TIniFile.Create(pINIFileName);

try

   lSections := TStringList.Create;

   try

     lItems := TStringList.Create;

     try

       lINIFile.ReadSections(lSections);

       for iSections := 0 to pred(lSections.Count) do

       begin

         lItems.Clear;

         lINIFile.ReadSection(lSections[iSections], lItems);

         lNode := pXML.AddChild(StringReplace(lSections[iSections], ' ', '',

           [rfReplaceAll]));

         for iItems := 0 to pred(lItems.Count) do

         begin

           if AsAttributes then

             lNode.Attributes[lItems[iItems]] :=

               lINIFile.ReadString(lSections[iSections], lItems[iItems], '')

           else

             lNode.AddChild(lItems[iItems]).Text :=

               lINIFile.ReadString(lSections[iSections], lItems[iItems], '');

         end;

         lNode := nil;

       end;

     finally lItems.Free;

     end;

   finally lSections.Free;

   end;

finally lINIFile.Free;

end;

end;

相关阅读 >>

Delphi android.os获取sn号

Delphi xe10 android 界面设计-个人心得

Delphi 语法基础: 使用不同的数据类型标记数组

Delphi 如何判断html编码格式,解决乱码问题

Delphi 将base64字符串转化为jpeg图片

Delphi 金木水火土 生克用法

Delphi 窗体只显示控件

Delphi fmx检查应用程序状态更改

Delphi 自带的 base64 编解码函数

Delphi中url的汉字编码

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...