Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1068381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:16:46+00:00 2026-05-16T20:16:46+00:00

can anyone help me to learn how to use XML. As a test i

  • 0

can anyone help me to learn how to use XML. As a test i want to use XML instead of INI files for saving a program settings.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:16:46+00:00Added an answer on May 16, 2026 at 8:16 pm

    Rigo, you can use the IXMLDocument interface or the TXMLDocument object to interact with a XML document.

    You can check these links for more information about XML and Delphi

    • Creating, Parsing and Manipulating XML Documents with Delphi
    • Xml Serialization – Basic Usage (Delphi 2010)
    • Practical XML in Delphi (From @Jeroen)

    Check this sample code , to learn the basics about xml management using the IXMLDocument interface.

    program Delphi_XmlSaveSettings;
    
    {$APPTYPE CONSOLE}
    uses
      ActiveX,
      SysUtils,
      XmlDoc,
      XmlIntf;
    //this class mimic the basics functionalities of an TIniFile
    //you can improve a lot the code adding exception handling and more methods for specifics tasks.
    type
      TXMLSettings = class 
      private
        FFileName: string;
        FXMLDoc: IXMLDocument; //Main XMLObject
      public
        constructor Create(const FileName: string); overload;
        destructor  Destroy; override;
        function    ReadString(const Section, Key, default: string): string;
        procedure   WriteString(const Section, Key, Value: string);
        function    ReadInteger(const Section, Key: string; default: Integer): Integer;
        procedure   WriteInteger(const Section, Key: string; Value: Integer);
        function    ReadBoolean(const Section, Key: string; default: Boolean): Boolean;
        procedure   WriteBoolean(const Section, Key: string; Value: Boolean);
        function    ReadDouble(const Section, Key: string; default: Double): Double;
        procedure   WriteDouble(const Section, Key: string; Value: Double);
        function    ReadDateTime(const Section, Key: string; default: TDatetime): TDateTime;
        procedure   WriteDatetime(const Section, Key: string; Value: TDatetime);
        function    ReadDate(const Section, Key: string; default: TDatetime): TDateTime;
        procedure   WriteDate(const Section, Key: string; Value: TDatetime);
        procedure   Save;
      end;
    
    
    
    constructor TXMLSettings.Create(const FileName: string);
    begin
      inherited Create;
      FFileName       := FileName;
      FXMLDoc         := NewXMLDocument; //Create  aNew instance of a XML Document
      FXMLDoc.Encoding:= 'UTF-8'; //Set the encoding
      FXMLDoc.Options := [doNodeAutoIndent];//optional, is used to indent the Xml document
    
      if FileExists(FFileName) then
        FXMLDoc.LoadFromFile(FFileName)
      else
        FXMLDoc.AddChild('Root'); //Create the root Node
    end;
    
    
    destructor TXMLSettings.Destroy;
    begin
      Save;
      inherited;
    end;
    
    function TXMLSettings.ReadBoolean(const Section, Key: string; default: Boolean): Boolean;
    begin
      Result := Boolean(ReadInteger(Section, Key, Integer(default)));
    end;
    
    function TXMLSettings.ReadDate(const Section, Key: string; default: TDatetime): TDateTime;
    begin
      Result := StrToDate(ReadString(Section, Key, DateToStr(default)));
    end;
    
    function TXMLSettings.ReadDateTime(const Section, Key: string; default: TDatetime): TDateTime;
    begin
      Result := StrToDateTime(ReadString(Section, Key, DateTimeToStr(default)));
    end;
    
    function TXMLSettings.ReadDouble(const Section, Key: string;  default: Double): Double;
    begin
      Result := StrToFloat(ReadString(Section, Key, FloatToStr(default)));
    end;
    
    function TXMLSettings.ReadInteger(const Section, Key: string; default: Integer): Integer;
    begin
      Result := StrToInt(ReadString(Section, Key, IntToStr(default)));
    end;
    
    function TXMLSettings.ReadString(const Section, Key, default: string): string; 
    var
      XMLNode: IXMLNode;
    begin
      XMLNode := FXMLDoc.DocumentElement.ChildNodes.FindNode(Section);
      if Assigned(XMLNode) and XMLNode.HasAttribute(Key) then //Check if exist the Key
        Result := XMLNode.Attributes[Key]
      else
        Result := default;
    end;
    
    procedure TXMLSettings.Save;
    begin
      FXMLDoc.SaveToFile(FFileName);
    end;
    
    procedure TXMLSettings.WriteBoolean(const Section, Key: string; Value: Boolean);
    begin
      WriteInteger(Section, Key, Integer(Value));
    end;
    
    procedure TXMLSettings.WriteDate(const Section, Key: string; Value: TDatetime);
    begin
      WriteString(Section, Key, DateToStr(Value));
    end;
    
    procedure TXMLSettings.WriteDatetime(const Section, Key: string;  Value: TDatetime);
    begin
      WriteString(Section, Key, DateTimeToStr(Value));
    end;
    
    procedure TXMLSettings.WriteDouble(const Section, Key: string; Value: Double);
    begin
      WriteString(Section, Key, FloatToStr(Value));
    end;
    
    procedure TXMLSettings.WriteInteger(const Section, Key: string; Value: Integer);
    begin
      WriteString(Section, Key, IntToStr(Value));
    end;
    
    procedure TXMLSettings.WriteString(const Section, Key, Value: string);
    var
      XMLNode: IXMLNode;
    begin
      XMLNode := FXMLDoc.DocumentElement.ChildNodes.FindNode(Section);
      if not Assigned(XMLNode) then
      XMLNode := FXMLDoc.DocumentElement.AddChild(Section);
      XMLNode.Attributes[Key] := Value;
    end;
    
    
    Procedure SaveSettings; //Store the settings
    Var
      AppSettings :  TXMLSettings;
    begin
      AppSettings:=TXMLSettings.Create(ExtractFilePath(ParamStr(0))+'MySettings.xml');
      try
       AppSettings.WriteString('Server','Type','SQLServer');
       AppSettings.WriteString('Server','User','root');
       AppSettings.WriteInteger('Server','port',1433);
       AppSettings.WriteString('Server','IP','192.168.1.1');
       AppSettings.WriteString('Server','Database','Prod');
       AppSettings.WriteBoolean('Server','WindowsAuth',False);
       AppSettings.WriteDouble('Server','Latency',25.90892);
       AppSettings.WriteDatetime('Server','LastAccess',Now);
       AppSettings.WriteDate('Server','ActualDate',Now);
       AppSettings.Save;
      finally
      AppSettings.Free;
      end;
      Writeln('Settings Saved');
    end;
    
    
    Procedure ShowSettings;//Read the settings
    Var
      AppSettings :  TXMLSettings;
    begin
      AppSettings:=TXMLSettings.Create(ExtractFilePath(ParamStr(0))+'MySettings.xml');
      try
       Writeln(Format('Type         %s',[AppSettings.ReadString('Server','Type','')]));
       Writeln(Format('Port         %d',[AppSettings.ReadInteger('Server','port',0)]));
       Writeln(Format('IP           %s',[AppSettings.ReadString('Server','IP','')]));
       Writeln(Format('Database     %s',[AppSettings.ReadString('Server','Database','')]));
       Writeln(Format('WindowsAuth  %s',[BoolToStr(AppSettings.ReadBoolean('Server','WindowsAuth',True),True)]));
       Writeln(Format('Latency      %g',[AppSettings.ReadDouble('Server','Latency',0)]));
       Writeln(Format('LastAccess   %s',[DateTimeToStr(AppSettings.ReadDateTime('Server','LastAccess',Now-1))]));
       Writeln(Format('ActualDate   %s',[DateToStr(AppSettings.ReadDate('Server','ActualDate',Now-1))]));
      finally
      AppSettings.Free;
      end;
    end;
    
    begin
      try
        CoInitialize(nil); //only necesary in console applications
        try
          SaveSettings; //Save the sample settings
          ShowSettings; //Read the stored settings
          Readln;
        finally
        CoUninitialize; //only necesary in console applications
        end;
      except
        on E:Exception do
          Writeln(E.Classname, ': ', E.Message);
      end;
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone help me with the trying to write SQL (MS SqlServer) - I
I just forgot the password. Can anyone help me how to get back the
Wondering if anyone can help me with this annoying but trivial (in terms of
I was wondering if anyone can help me get started with creating a room
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
Can anyone suggest some good browser add-on tools/extensions to help with development? I have
Can anyone recommend a good resource -- book, website, article, etc -- to help
Are there some help resources, or can anyone give me a brief Idea how
Can anyone tell me how I can display a status message like 12 seconds
Can anyone recommend a good library for generating an audio file, such as mp3,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.