This article describes how to include the <xml version="1.0" > header in COBOL output when using XML Syntax Extensions.
Problem:
When using XML Syntax Extensions, the COBOL output does not include the <xml version="1.0" > header.
Resolution:
The <?xml version="1.0"?> header is actually an XML Processing Instruction so you need to output it using the Syntax for Processing Instructions. For example:
$set preprocess(prexml) o(foo.pp) warn endp
select xml-stream assign "out.xml"
organization is xml
document-type is omitted
file status is xml-bookdb-status.
xd xml-stream.
01 xmls-group identified by "group".
05 xmls-Number pic 9(18)
identified by "elementNumber" is attribute.
05 xmls-Alpha pic x(80)
identified by "elementAlpha".
working-storage section.
01 xml-bookdb-status pic s9(9) comp.
procedure division.
move 1235 to xmls-Number
move "Alpha value" to xmls-Alpha
open output xml-stream
write xmls-group key is all xmls-group
start xml-stream key is xmls-group
write xmls-group key is processing-instruction
'xml version="1.0" encoding="UTF-8"'
write xmls-group
close xml-stream
stop run.
Outputs the following XML stream:
<?xml version="1.0" encoding="UTF-8"?>
<group elementNumber="1235">
<elementAlpha>Alpha value</elementAlpha>
</group>