@edward-h added XML GENERATE
completely and the bigger parts of XML PARSE
in the compiler.
GnuCOBOL uses libxml2 for XML handling which seems to provide an API similar to XML PARSE
, see control flow; in general the xml document is parsed in stream mode and when "events" are happening (start/end/fragment found/error occurred) a procedure is executed after special registers, mostly XML-EVENT
and XML-TEXT
, are set.
Different docs with nearly same content: registers and content of XML-EVENT
: https://www.microfocus.com/documentation/visual-cobol/vc80/DevHub/HRLHLHCLANU020.html and, with content for XML-CODE
https://www.microfocus.com/documentation/visual-cobol/vc80/DevHub/HRLHLHAXME01.html
After first discussions with @articuno this FR ticket will be the place to discuss more details and track the process.
Current state:
cob_field
s for the registers and there are a multitude of functions to set those from C strings and integersint cob_xml_parse (cob_field *data, cob_field *encoding, cob_field *validation, int flags, void **state)
(encoding and validation are optional, the only flag used so far is 1 = "set the national registers")data
, set XML-CODE
, XML-EVENT
, XML-TEXT
, ... by provided functionsset_xml_code()
and friendsPROCESSING PROCEDURE
[NOT] ON EXCEPTION
statements as appropriateThings to do:
ANY LENGTH
parts needed for XML registersXML PARSE
, including the XML-SCHEMA
definition in SPECIAL NAMES
XML PARSE
as the specific loop, state variable and exception check after loop.. is special (similar to SEARCH
)xml_parse
using libxml2 (planned to be done by @articuno)Things that can be postponed and may either be done last - or "in a later iteration": * handle validation * handle encoding * handle national * cobc: more checks for the parameters
Discussion: IBM COBOL XML Parsing
Discussion: GSOC24 - Implement XML PARSE in GnuCOBOL using libxml2
Discussion: IBM COBOL for Linux
There is sample code (both snipped and a complete program [which contains
EXEC SQL
so needs an esql preprocessor] at [6f24010e48] - and likely someone that can test with CI builds on a bigger source code, too.Related
Discussion: 6f24010e48
Diff:
I've found an IBM sample that cannot be used in the testsuite - but as a local test during development: https://www.ibm.com/docs/en/cobol-zos/6.3?topic=examples-example-program-processing-xml (which also showed an issue with PROCESS/CBL statement not handled in column 1-7).
After two days of work the parsing, codegen and the runtime part outside of using libxml2 in
xml_parse
is quite complete. I hope to finish that tomorrow, allowing @articuno to do the implementation.Checked in everything but actual XML parsing with [r4686] @articuno: have fun!
Related
Commit: [r4686]
Moved over to the next person to become famous :-)
Ticked moved on, Ammar started this as GSOC project and after the need to withdraw from the project wants to go on with it, likely in September 2024.