我把TXMLDocument放在一个窗体上,用它来生成XML文件,但是每次打开这个窗体后就只能生成一个文件,如果想再生成一个文件就会出现如下错误:Access violation at address 008c086b in module 'project1.exe' .Read of address 000000000 .process stopped.use step or run to continue.只能把这个窗体关闭后再开才可以正确生成。请问是不是生成完后,要调用那个函数来释放,请各位指教!!
XMLDocument1.Active := True;
XMLDocument1.Encoding := 'UTF-8';
XMLDocument1.XML.Add('<COMFIRM xmlns="http://shedi.com/comfirm.xsd">');
XMLDocument1.XML.Add('</COMFIRM>');
XMLDocument1.Active := True;
containers:=XMLDOCUMENT1.DocumentElement.AddChild('CONTAINERS');
with XMLDocument1 do
begin
Container:=CONTAINERS.AddChild('CONTAINER');
Container.AddChild('SHIP_ID').NodeValue:=svsl_callsign;
container.AddChild('VOYAGE').NodeValue:=svoy_code;
container.AddChild('BILL_NUMBER').NodeValue:=sBlno;
container.AddChild('CONT_NUMBER').NodeValue:=Sctn_code;
container.AddChild('SAIL_QUAY').NodeValue:=Sfwhf_custcode;
end;
XMLDocument1.SaveToFile(filename);
XMLDocument1.Active:=false;
XMLDocument1.free;
你把它释放了,下次用它当然要出错.
XMLDocument1.free;
only one top level element is allowed in XMLDocument请各位指导指导,急用。。
感觉方便些
XMLDocument1.XML.Add('<COMFIRM xmlns="http://shedi.com/comfirm.xsd">');
XMLDocument1.XML.Add('</COMFIRM>');
XMLDocument1.Active := True;
XMLDocument1.Encoding := 'UTF-8';
containers:=XMLDOCUMENT1.DocumentElement.AddChild('CONTAINERS');
with XMLDocument1 do
begin
Container:=CONTAINERS.AddChild('CONTAINER');
Container.AddChild('SHIP_ID').NodeValue:='svsl_callsign';
container.AddChild('VOYAGE').NodeValue:='svoy_code';
container.AddChild('BILL_NUMBER').NodeValue:='sBlno';
container.AddChild('CONT_NUMBER').NodeValue:='Sctn_code';
container.AddChild('SAIL_QUAY').NodeValue:='Sfwhf_custcode';
end;
XMLDocument1.SaveToFile('d:\test.xml');
XMLDocument1.Active:=false;