问题
I've been googling for a while,but i could'nt find the right example.
I have local XML with with Node
And I have a form in my project:
Edit1 | Submit
I want the when user hits Submit childNode to be created in my XML file for categories. Like:
<categories>
<cat1>Name of Cat(Edit1.Text)</cat1>
</categories>
EDIT:
I have Project1.XML file in my .exe directory (/Win32/Debug/Project1.XML):
<Kategorijos>
</Kategorijos>
In my Form there is an input field (Edit1) and a button (Button1)
On button click program should load Project1.XML, find <Kategorijos>
and add childNode(<cat1>Edit1.Text</cat1>
) to it, so it would look like this if Edit1 input value would be equal to 'My first category.':
<Kategorijos>
<cat1>My first caregory</cat1>
</Kategorijos>
I use XE3.
回答1:
Maybe some newbies like me will find this solution I finally found useful:
procedure Tform1.addCat (kategorija : string);
var
Doc: IXMLDocument;
data: IXMLNode;
xmlNode : IXMLNode;
newCat : IXMLNode;
begin
Doc := LoadXMLDocument('Project1.XML');
data := Doc.DocumentElement;
xmlNode := data.ChildNodes.FindNode('Kategorijos');
newCat := xmlNode.AddChild('cat1');
newCat.Text := kategorija;
Doc.SaveToFile('Project1.XML');
end;
来源:https://stackoverflow.com/questions/23030426/delphi-load-xml