delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
493 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi



Loremo - the 1.5 liter car coming in 2009




Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (0)


INI to XMLGo to Jim McKeeth's websiteFormat this article printer-friendly!Bookmark function is only available for registered users!
Convert an INI file to XML
Product:
Delphi 6.x (or higher)
Category:
XML
Skill Level:
Scoring:
Last Update:
05/05/2003
Search Keys:
delphi delphi3000 article borland vcl code-snippet XML INI XMLIntf XMLDoc IniFiles TINIFile TXMLDocument IXMLNode
Times Scored:
4
Visits:
5619
Uploader: Jim McKeeth
Company: Boise Software Developers
Reference: N/A
 
Question/Problem/Abstract:
INI was the old way to store settings (outside the registry), now everything is XML. This routine will convert an INI file into an XML node of a document.
Answer:



An XML node is part of an XML Document.  So if you have a new XMLDocument then just add a single node (AddChild) and that is the DocumentNode, then you could pass the DocumentNode to this routine.  If you pass in different Nodes then you could store multiple INI files in the same XML document, even if they have section and value name collisions.  The AsAttributes parameter determines if the values are stored as Attributes (default) or sub-nodes.  

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;






Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment













 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
D. Souchard
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)