Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Modify an XML document

Posted on 2005-03-22
4
Medium Priority
?
195 Views
Last Modified: 2010-04-05
Okay, I have a program written in Delphi 6 that opens an XML document and can view content.  What I want to do is change the content, but I have no idea where to begin.  I've looked all over and cannot find a simple answer.  I'm hoping I don't have to use constructs, xsl or all that other crap.  It seems like if I'm getting a "node" I should just as simply be able to edit it.  Anyway, here's the XML file:

______________________________________

<?xml version="1.0"?>
<Users>
   <Character>
      <name>Scott</name>
      <password>test</password>
      <gender>male</gender>
   </Character>
   <Character>
      <name>Aeolus</name>
      <password>test</password>
      <gender>male</gender>
   </Character>
   <Character>
      <name>Bob</name>
      <password>pwforbob</password>
      <gender>male</gender>
   </Character>
   <Character>
      <name>Fred</name>
      <password>fredspw</password>
      <gender>Male</gender>
   </Character>
</Users>
___________________________________

and here's the code:
___________________________________

procedure TForm1.FormCreate(Sender: TObject);
begin
   XMLDoc.LoadFromFile('c:\project\server\users.xml');
   XMLDoc.Active := true;

   StartItemNode := XMLDoc.DocumentElement.ChildNodes.FindNode('Character');
   CharNode := StartItemNode;
   repeat
    ListBox1.AddItem(CharNode.ChildNodes['name'].Text,nil);
    CharNode := CharNode.NextSibling;
   until CharNode = nil;

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
   CharNode := StartItemNode;
   repeat
    if CharNode.ChildNodes['name'].Text = TListBox(Listbox1).Items[TListBox(Listbox1).ItemIndex] then
    ShowMessage (CharNode.ChildNodes['password'].Text);
    CharNode := CharNode.NextSibling;
   until CharNode = nil;
end;

_________________________________

As you can see, it gets all the <name>'s and pupulates a listbox.  Then, if you select one of the names and click "show password" it shows you the <password> from that <name>.  What I want to do is add an EditBox and another button and be able to change the <password> for the selected <name>.  I have no idea where to begin.
0
Comment
Question by:Cerixus
  • 2
4 Comments
 
LVL 1

Author Comment

by:Cerixus
ID: 13607701
Holy crap, it's like a billion times easier than I expected...

All I did was this:

      CharNode.ChildNodes['password'].Text := Edit1.Text;
      XMLDoc.SaveToFile('c:\project\server\users.xml');

I'm diggint XML...  Sorry for the pointless question, but maybe it will help someone else :)
0
 
LVL 1

Author Comment

by:Cerixus
ID: 13607703
*digging :)

Please close this question.
0
 
LVL 46

Expert Comment

by:aikimark
ID: 13609041
You need to post a question in the Community Support forum to request this question be closed PAQ with points refund.
0
 

Accepted Solution

by:
PashaMod earned 0 total points
ID: 14071554
Closed, 500 points refunded.
PashaMod
Community Support Moderator
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question