Delphi加载XML [英] Delphi load XML
问题描述
我已经搜索了一段时间,但是找不到合适的示例。
I've been googling for a while,but i could'nt find the right example.
我的本地XML与Node一起使用
I have local XML with with Node
我的项目中有一个表单:
And I have a form in my project:
Edit1 |提交
我希望在用户单击提交子节点时在我的XML文件中创建类别。
喜欢:
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>
编辑:
我有Project1。我的.exe目录中的XML文件(/Win32/Debug/Project1.XML):
I have Project1.XML file in my .exe directory (/Win32/Debug/Project1.XML):
<Kategorijos>
</Kategorijos>
在我的表单中有一个输入字段(Edit1)和一个按钮(Button1)
In my Form there is an input field (Edit1) and a button (Button1)
单击按钮时,程序应加载Project1.XML,找到< Kategorijos>
并添加childNode(< ; cat1> Edit1.Text< / cat1>
),因此,如果Edit1输入值等于我的第一类,它将看起来像这样。
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>
我使用XE3。
推荐答案
也许像我这样的新手会发现我终于找到了有用的解决方案:
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;
这篇关于Delphi加载XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!