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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With