Delphi load XML

随声附和 提交于 2019-12-24 00:26:36

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!