Why is encoding attribute missing in XML generated by COBOL?

Viewed 101

What could be the reason for difference in expected and actual output of below program? Actual output is missing encoding.

       IDENTIFICATION DIVISION.
       PROGRAM-ID. FOO.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 doc PIC X(512).
       01 Greeting.
           05 msg PIC X(80) VALUE "Hello, world!".

       PROCEDURE DIVISION.
           XML GENERATE doc FROM Greeting
               WITH ENCODING 1208
               WITH XML-DECLARATION
           END-XML
           DISPLAY doc.
           STOP RUN.

The code compiled successfully. I'm using Visual COBOL 5.0 by Micro Focus.

Expected Output:

<?xml version="1.0" encoding="UTF-8"?>
<Greeting><msg>Hello, world!</msg>
</Greeting>

Actual output:

<?xml version="1.0" ?><Greeting>
<msg>Hello, world!</msg></Greeting>
1 Answers

XML only accepts two types of encoding, utf-8 and utf-16, utf-8 being the default. From the documentation, it looks like the encoding is only necessary if it is not utf-8. Since leaving it out is legal the clause is not generated.

For utf-16 encoding, change doc to

01 doc PIC n(512) usage national.

If you look at https://www.microfocus.com/documentation/visual-cobol/VC232/EclWin/HRLHLHPDFC0G.html (Web page for MicroFocus XML GENERATE) it says that the ENCODING statement is documentary only so that does not generate any code either.

Related