2

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.

user1804119
  • 142
  • 3
  • 12
  • 1
    To a vague question a vague answer. By using [`OXML`](http://stackoverflow.com/a/20553999/960757), you can write [`something like this`](http://pastebin.com/nmy0N1zt). – TLama Apr 12 '14 at 12:53
  • Hi TLama, i've created a procedure from your example http://pastebin.com/0nrHdPKs, but i get an error: class Txmldocument not found. – user1804119 Apr 12 '14 at 13:16
  • @user1804119 Edit your question and include the relevant parts of the code. "I have local XML with Node" says nothing. Also give us input, expected output, any errors. – Jan Doggen Apr 12 '14 at 14:53
  • 1
    And if you get a 'class not found' for any component, you put the cursor in it, press Ctrl-F1 and the help will tell you in which unit it is declared. Then put that unit in your Uses clause. – Jan Doggen Apr 12 '14 at 14:54
  • I've made changes on the main post. It should be clear now. – user1804119 Apr 12 '14 at 16:34
  • Surely you can start from the Delphi xml docs – David Heffernan Apr 12 '14 at 16:47

1 Answers1

2

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;
user1804119
  • 142
  • 3
  • 12