Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to convert an INI file to XML Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
15-Jun-03
Category
XML
Language
Delphi 6.x
Views
214
User Rating
10
# Votes
2
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jim McKeeth 

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.   

1   uses XMLIntf, XMLDoc, INIFiles;
2   
3   procedure INI2XML(const pINIFileName: string; const pXML: IXMLNode;
4     const AsAttributes: Boolean = true);
5   var
6     lINIFile: TIniFile;
7     lSections, lItems: TStringList;
8     iSections, iItems: integer;
9     lNode: IXMLNode;
10  begin
11    lINIFile := TIniFile.Create(pINIFileName);
12    try
13      lSections := TStringList.Create;
14      try
15        lItems := TStringList.Create;
16        try
17  
18          lINIFile.ReadSections(lSections);
19  
20          for iSections := 0 to pred(lSections.Count) do
21          begin
22            lItems.Clear;
23            lINIFile.ReadSection(lSections[iSections], lItems);
24            lNode := pXML.AddChild(StringReplace(lSections[iSections], ' ', '',
25              [rfReplaceAll]));
26            for iItems := 0 to pred(lItems.Count) do
27            begin
28              if AsAttributes then
29                lNode.Attributes[lItems[iItems]] :=
30                  lINIFile.ReadString(lSections[iSections], lItems[iItems], '')
31              else
32                lNode.AddChild(lItems[iItems]).Text :=
33                  lINIFile.ReadString(lSections[iSections], lItems[iItems], '');
34            end;
35            lNode := nil;
36          end;
37  
38        finally lItems.Free;
39        end;
40      finally lSections.Free;
41      end;
42    finally lINIFile.Free;
43    end;
44  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC