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 6976115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:27:19+00:00 2026-05-27T17:27:19+00:00

I want to write some code (in Delphi) to get this XML scheme, I

  • 0

I want to write some code (in Delphi) to get this XML scheme, I tried but no result as I want, could you help me !
I use (or want use) IXMLDocument created at runtime, but I can’t understand “Nodes”, “ChildNodes” … I know, it’s ridiculous !

This is the scheme example I want :

<Items>
 <Task id="eec0-47de-91bc-98e2d69d75cd">
   <Title>The title of something</Title>
   <State>Done</State>
   <IdNoHashed>This Is a string</IdNoHashed>
   <CreatedDate>28/12/2011 06:24:57</CreatedDate>
   <Note>Just a note</Note>
 </Task>
 <Task id="e2x5d4-2d45c-98e2d69d75cd">
   <Title>Another title</Title>
   <State>Done</State>
   <IdNoHashed>This Is a string 2</IdNoHashed>
   <CreatedDate>28/12/2011 22:22:22</CreatedDate>
   <Note>Just a note, again !</Note>
 </Task>
</items>

Do you have a suggestion ?
Thank you !

EDIT : I Tried the code answered below, It works fine, but when I want to add any other entry in the Root, it rewrites the already-exist element.

Function WriteData (id, title, state, idNH : String) : Boolean;
 var
   Doc: IXMLDocument;
   Items, Task: IXMLNode;
begin
  Doc := NewXMLDocument;
  Items := Doc.AddChild('Items');

  Task := Items.AddChild('Task');
  Task.Attributes['id'] := id;
  Task.AddChild('Title').Text := title;
  Task.AddChild('State').Text := state;
  Task.AddChild('IdNoHashed').Text := idNH;
  Task.AddChild('CreatedDate').Text := DateTimeToStr(Now);
  Task.AddChild('Note').Text := 'Just a note';
end;

I tried DocumentElement.ChildNodes.FindNode(id), but not success !

I created a function which I call each time to add/modify an entry in the XML file, the entry is “”.
An idea to how can I do this ?!
Thank you !

  • 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-27T17:27:20+00:00Added an answer on May 27, 2026 at 5:27 pm

    Check this sample application which uses the IXMLDocument interface, the comments in the source explains how the elements are added

    {$APPTYPE CONSOLE}
    
    {$R *.res}
    
    uses
      ActiveX,
      XMLIntf,
      XMLDoc,
      SysUtils;
    
    procedure Test;
    Var
      XML : IXMLDocument;
      RootNode, Node, CNode : IXMLNode;
    begin
      XML := NewXMLDocument;//initializate the interface
      XML.Options := [doNodeAutoIndent];//activate the auto indentation
      RootNode := XML.AddChild('Items');//add the root node
      Node := RootNode.AddChild('Task');//add the task node
      Node.Attributes['id'] := 'eec0-47de-91bc-98e2d69d75cd';//<Task id="eec0-47de-91bc-98e2d69d75cd">
       CNode:=Node.AddChild('Title');//add the title node
       CNode.Text:='The title of something';//<Title>The title of something</Title>
       CNode:=Node.AddChild('State');//add the State node
       CNode.Text:='Done'; //<State>Done</State>
       CNode:=Node.AddChild('IdNoHashed');//add the IdNoHashed node
       CNode.Text:='This Is a string'; //<IdNoHashed>This Is a string</IdNoHashed>
       CNode:=Node.AddChild('CreatedDate');//add the CreatedDate node
       CNode.Text:=FormatDateTime('dd/mm/yyyy hh:nn:ss',EncodeDate(2011,12,28)+EncodeTime(6,24,57,0));//<CreatedDate>28/12/2011 06:24:57</CreatedDate>
       CNode:=Node.AddChild('Note');//Add the Note node
       CNode.Text:='Just a note'; //<Note>Just a note</Note>
    
      //repeat the process again for the second task node    
      Node := RootNode.AddChild('Task');
      Node.Attributes['id'] := 'e2x5d4-2d45c-98e2d69d75cd';
       CNode:=Node.AddChild('Title');
       CNode.Text:='Another title';
       CNode:=Node.AddChild('State');
       CNode.Text:='Done';
       CNode:=Node.AddChild('IdNoHashed');
       CNode.Text:='This Is a string 2';
       CNode:=Node.AddChild('CreatedDate');
       CNode.Text:=FormatDateTime('dd/mm/yyyy hh:nn:ss',EncodeDate(2011,12,28)+EncodeTime(22,22,22,0));
       CNode:=Node.AddChild('Note');
       CNode.Text:='Just a note, again !';
    
      Writeln(XML.XML.Text); //Show the output
    end;
    
    
    begin
     try
        CoInitialize(nil); //use this just in console apps
        try
          Test;
        finally
          CoUninitialize;//use this just in console apps
        end;
     except
        on E:Exception do
            Writeln(E.Classname, ':', E.Message);
     end;
     Writeln('Press Enter to exit');
     Readln;
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write some code that need to use artificial intelligence. I dont
I want to write some html code in php. In this html code I
Say you write some code like this (using ruby-mode, but I've seen this happen
I want to write some games, but I don't have any game development experience.
I want to use Powershell to write some utilities, leveraging our own .NET components
I want to convert 24 byte BCD to ASCII.Im trying to write some code
need some help! I'm trying to write some code in objective-c that requires part-of-speech
I want to write some code in my rails view page to define a
I want to write some code that allows me to replace jQuery's animate function
I want to write some library code to be shared across products and across

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.