How can I add version and encoding to an XML file using TXMLDocument

I want to add version and encodig to xml file created using TXMLDocumentcomponent

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

Now i do it

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

but I get an access violation on this line

XmlDoc.Version:='1.0';

How can I add version and encoding?

+5
source share
2 answers

Before changing the properties of an XML document, you must set the property Activeto True.

XmlDoc   :=TXMLDocument.Create(nil);
XmlDoc.Active:=True;
XmlDoc.Version:='1.0';
XMLDoc.Encoding:='utf-8';
+17
source

TXMLDocument nil, , IXMLDocument , . TXMLDocument . AV. TXMLDocument NewXMLDocument() LoadXML...().

+1

All Articles