Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how i can add the version and encoding to a xml file using TXMLDocument

i want to add the version and encodig to a xml file created with TXMLDocument component

<?xml version="1.0" encoding="utf-8"?>

curently i'm doing this

XmlDoc   :=TXMLDocument.Create(nil);
XmlDoc.Version:='1.0';
XMLDoc.Encoding:='utf-8';

but i receive an acces violation in this line

XmlDoc.Version:='1.0';

how i can add the version and encoding?

like image 373
Salvador Avatar asked Mar 18 '11 22:03

Salvador


2 Answers

you must set the Active property to True before to modify the XML document properties.

XmlDoc   :=TXMLDocument.Create(nil);
XmlDoc.Active:=True;
XmlDoc.Version:='1.0';
XMLDoc.Encoding:='utf-8';
like image 165
RRUZ Avatar answered Sep 29 '22 00:09

RRUZ


If you construct a TXMLDocument with a nil Owner, the new instance uses reference counting to maintain its lifetime, so you MUST assign it to an IXMLDocument variable to maintain the reference count correctly or else the instance will be freed prematurely. Do not use a TXMLDocument variable in that situation. This is documented behavior, and would account for your AV. When working with dynamic instances of TXMLDocument, it is better to use the NewXMLDocument() and LoadXML...() functions instead.

like image 36
Remy Lebeau Avatar answered Sep 29 '22 00:09

Remy Lebeau