Hello
Based on
http://wiki.freepascal.org/XML_Tutorial I tried to insert a new node to an existing document.
<?xml version="1.0" encoding="UTF-8"?>
<register>
<usuario id="001">
<nome>Fernando</nome>
<idade>32</idade>
<item nome="Item" arquivo="Arquivo"/>
</usuario>
<item id="002">
...
</item>
</register>
I want to insert any item with e.g. id="002" to the existing xml.
I tried:
procedure ExportXML();
var Doc: TXMLDocument;
NovoNo: TDomNode;
begin
ReadXMLFile(Doc, 'c:\temp\test.xml');
NovoNo := Doc.CreateElement('item');
TDOMElement(NovoNo).SetAttribute('nome', 'Item');
TDOMElement(NovoNo).SetAttribute('arquivo', 'Arquivo');
Doc.DocumentElement.ParentNode.AppendChild(NovoNo);
writeXMLFile(Doc, 'c:\temp\test.xml');
end;
.. and got an exception. What did I wrong and how can I achieve it just add new nodes to existing documents. Thank you.