6

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?

2 Answers 2

18

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';
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.