I'm new to delphi and now I have to read create an xml. my code is the following:
unit writexml1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, xmldom, XMLIntf, StdCtrls, msxmldom, XMLDoc;
type
TForm1 = class(TForm)
XMLDocument1: TXMLDocument;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.SaveClick(Sender: TObject);
var
rootName: String;
childNode: String;
attrChild: string;
iXml: IDOMDocument;
iRoot, iNode, iNode2, iChild, iAttribute: IDOMNode;
XMLDoc: TXMLDocument;
begin
XMLDoc.Active := False;
XMLDoc.XML.Text := '';
XMLDoc.Active := True;
XMLDoc.SaveToFile('C:\Documents and Settings\a\Desktop\zulfa.xml');
iXml := XMLDoc.DOMDocument;
iRoot := iXml.appendChild(iXml.createElement('xml'));
iNode := iRoot.appendChild(iXml.createElement('test'));
iNode.appendChild(iXml.createElement('test2'));
iChild := iNode.appendChild(iXml.createElement('test3'));
iChild.appendChild(iXml.createElement('Simple calue'));
iNode.insertBefore(iXml.createElement('test4'), iChild);
iNode2 := iNode.cloneNode(True);
iRoot.appendChild(iNode2);
iAttribute := iXml.createAttribute('color');
iAttribute.nodeValue := 'red';
iNode2.attributes.setNamedItem(iAttribute);
end;
end.
The problem is that while clicking the save button it shows the exception ,the exception is
Project writexml1.exe raised exception class EAccessViolation with message 'Access violation at address 004391B9 in module writexml.exe