Unit unit1;
Interface
Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, xmldom, xmlintf, msxmldom, xmldoc, MSXML, stdctrls;
Type
Tform1 = Class (tform)
Btn1: tbutton;
Xmldocument1: txmldocument;
Procedure btn1click (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;
VaR
Form1: tform1;
Implementation
{$ R *. DFM}
Procedure tform1.btn1click (Sender: tobject );
VaR
Noderef: ixmldomnoderef;
Root: ixmldomnode;
Node: ixmldomnode;
Begin
Xmldocument1.loadfromfile ('test. xml ');
Xmldocument1.active: = true;
Noderef: = xmldocument1.documentelement. domnode as ixmldomnoderef;
Root: = noderef. getxmldomnode; // get the node
Node: = root. selectsinglenode ('itemlist/item [@ name = "name2"] '); // obtain the node based on the path property value
Showmessage (node. Attributes. getnameditem ('title'). Text); // title2
Node. attributes. getnameditem ('title '). text: = 'hello'; // <item name = "name2" Title = "title2"/>=> <item name = "name2" Title = "hello"/>
Xmldocument1.savetofile ('test. xml ');
End;
End.
Test. XML document:
<? XML version = "1.0" encoding = "UTF-8"?>
<Test>
<Itemlist>
<Item name = "name1" Title = "title1"> </item>
<Item name = "name2" Title = "title2"/>
</Itemlist>
</Test>