2

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>
Jorengarenar
  • 2,705
  • 5
  • 23
  • 60
Pawan
  • 21
  • 2
  • Possibly because 1208 is not a valid codepage. Try 65001 for UTF-8 – cup Aug 30 '21 at 12:26
  • Tried but didn't work. – Pawan Aug 31 '21 at 04:42
  • Have you tried removing the **WITH ENCODING** clause and adding an **XML SET ENCODING "utf-8"** before the generate statement? – cup Aug 31 '21 at 08:11
  • Microfocus XML manual can be found in https://www.microfocus.com/documentation/visual-cobol/VC40/xml-extensions-for-visual-cobol-40-users-guide.pdf – cup Aug 31 '21 at 08:12
  • It dint work !! anyway , m reading the docs to see if some library should be installed for XML generate statement. However , since there is no compilation error , i doubt that its library problem. i followed the XML generation logic from the link (https://www.microfocus.com/documentation/enterprise-developer/ed50pu3/ED-Eclipse/HRLHLHPDFC0G.html) . Every thing worked as per the statements mentioned in the link except Encoding. – Pawan Sep 01 '21 at 03:04

1 Answers1

2

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.

cup
  • 7,589
  • 4
  • 19
  • 42