开发者

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

开发者 https://www.devze.com 2023-02-18 06:24 出处:网络
i want to add the version and encodig to a xml file created with TXMLDocument component <?xml version=\"1.0\" encoding=\"utf-8\"?>

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';开发者_JS百科

how i can add the version and encoding?


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';


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消