Cerixus
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</passwo rd>
<gender>male</gender>
</Character>
<Character>
<name>Fred</name>
<password>fredspw</passwor d>
<gender>Male</gender>
</Character>
</Users>
__________________________ _________
and here's the code:
__________________________ _________
procedure TForm1.FormCreate(Sender: TObject);
begin
XMLDoc.LoadFromFile('c:\pr oject\serv er\users.x ml');
XMLDoc.Active := true;
StartItemNode := XMLDoc.DocumentElement.Chi ldNodes.Fi ndNode('Ch aracter');
CharNode := StartItemNode;
repeat
ListBox1.AddItem(CharNode. ChildNodes ['name'].T ext,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[T ListBox(Li stbox1).It emIndex] then
ShowMessage (CharNode.ChildNodes['pass word'].Tex t);
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.
__________________________
<?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</passwo
<gender>male</gender>
</Character>
<Character>
<name>Fred</name>
<password>fredspw</passwor
<gender>Male</gender>
</Character>
</Users>
__________________________
and here's the code:
__________________________
procedure TForm1.FormCreate(Sender: TObject);
begin
XMLDoc.LoadFromFile('c:\pr
XMLDoc.Active := true;
StartItemNode := XMLDoc.DocumentElement.Chi
CharNode := StartItemNode;
repeat
ListBox1.AddItem(CharNode.
CharNode := CharNode.NextSibling;
until CharNode = nil;
end;
procedure TForm1.Button1Click(Sender
begin
CharNode := StartItemNode;
repeat
if CharNode.ChildNodes['name'
ShowMessage (CharNode.ChildNodes['pass
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.
ASKER
*digging :)
Please close this question.
Please close this question.
You need to post a question in the Community Support forum to request this question be closed PAQ with points refund.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
All I did was this:
CharNode.ChildNodes['passw
XMLDoc.SaveToFile('c:\proj
I'm diggint XML... Sorry for the pointless question, but maybe it will help someone else :)