3
votes

I need to generate a XML file, and I have its schema in XSD format.

I created the classes using the XML Data Binding Wizard, but:

One of the requirements is that the xml has the encoding tag set to 'utf-8'.

I've done it before when creating xml's directly with IXMLDocument, by doing this:

var xml:IXMLDocument;
.
.
xml.Encoding:='utf-8';

The XML first line becomes < ? xml version="1.0" encoding="utf-8" ? >

But now, with the data binding wizard, I tried something similar:

var xml:IXMLAuditFile;
.
.
xml.OwnerDocument.Encoding:='utf-8';

But that encoding isn't showing in then xml file: < ? xml version="1.0" ? >

Is there any other place I should be setting the encoding when using the XML Data Binding?

Thank you Nuno

1
UTF-8 is the default encoding for XML, no need to specify it explicitelypf1957
Technically, there is no need. But the people who require this file (government) tell me it has to be there. And if the software doesn't meet their requirements, the certification they made can be revoked. So, I'll have to put it there, even if it is just for their eyes! :)nunopicado
So they want to certify you using a requirement that the XML spec itself specifically states is not required? Their own software that will be consuming your XML is not smart enough to conform to the same spec that everyone else conforms to? That's government thinking for you.Remy Lebeau
Hi Remy. No, not for me. For them. I went to the certification inspection just this January, and they (the inspectors) told me it had to be there. I'm not saying I agree, but if they want it, and it is possible, why not?nunopicado

1 Answers

1
votes

Just found the answer to my own question.

When I display the generated XML in a TMemo, the encoding is not shown. But when I save it to a file, the encoding is added, as long as I have the xml.Encoding property set.

Thank you all.