Link to home
Start Free TrialLog in
Avatar of Cerixus
CerixusFlag for United States of America

asked on

Modify an XML document

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.
Avatar of Cerixus
Cerixus
Flag of United States of America image

ASKER

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 :)
Avatar of Cerixus

ASKER

*digging :)

Please close this question.
Avatar of aikimark
You need to post a question in the Community Support forum to request this question be closed PAQ with points refund.
ASKER CERTIFIED SOLUTION
Avatar of PashaMod
PashaMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial