Visual COBOL - organization is xml

[Migrated content. Thread originally posted on 14 February 2011]

Hi,

i'm testing Visual Cobol with Eclipse and want to make an xml file.
When i use organization is xml, eclipse gives me a compilation error.

Documentation is here :

community.microfocus.com/.../7252_XML_Syntax__SELECT_Clause

Best regards,

Renzo
  • This seems to be a case where the documentation is ahead of the technology release.
    The XML preprocessor technology is not in the current Visual COBOL R3 release.

    It is slated for release in R4.

    The R3 release does support the XML GENERATE and XML PARSE statements.
    See: XML GENERATE
  • XML GENERATE gives me xml, but is not flexibel.

    I have the following in WORKING STORAGE :

    01 XML-DATA.
    03 XML-DATA-REC.
    05 XML-DATA-DETAIL OCCURS 100.
    07 XML-NUMBER PIC X(04).
    07 XML-STRING PIC X(40).

    When i only fill 3 rows in my table, and i use the following statement :

    XML GENERATE WS-XML-DATA FROM XML-DATA
    COUNT IN WS-XML-COUNT
    WITH XML-DECLARATION

    I get the following result :

    <?xml version="1.0" ?><XML-DATA><XML-DATA-REC><XML-DATA-DETAIL><XML-NUMBER>0001</XML-NUMBER><XML-STRING>TEST1</XML-STRING></XML-DATA-DETAIL><XML-DATA-DETAIL><XML-NUMBER>0002</XML-NUMBER><XML-STRING>TEST2</XML-STRING></XML-DATA-DETAIL><XML-DATA-DETAIL><XML-NUMBER>0003</XML-NUMBER><XML-STRING>TEST3</XML-STRING></XML-DATA-DETAIL><XML-DATA-DETAIL><XML-NUMBER> </XML-NUMBER><XML-STRING> </XML-STRING></XML-DATA-DETAIL><XML-DATA-DETAIL><XML-NUMBER> </XML-NUMBER><XML-STRING> </XML-STRING></XML-DATA-DETAIL>

    ...

    <XML-DATA-DETAIL><XML-NUMBER> </XML-NUMBER><XML-STRING> </XML-STRING></XML-DATA-DETAIL><XML-DATA-DETAIL><XML-NUMBER> </XML-NUMBER><XML-STRING> </XML-STRING></XML-DATA-DETAIL><XML-DATA-DETAIL><XML-NUMBER> </XML-NUMBER><XML-STRING> </XML-STRING></XML-DATA-DETAIL><XML-DATA-DETAIL><XML-NUMBER> </XML-NUMBER><XML-STRING> </XML-STRING></XML-DATA-DETAIL></XML-DATA-REC></XML-DATA>

    Can i generate xml without the empty fields from the table ?

    Regards,

    Renzo

  • Verified Answer

    XML GENERATE General Rule 8 states:
    If a character value consists only of spaces, one space remains as the value after trimming is finished.

    In order to remove the blank tags you can use an Occurs Depending On to limit the scope of the data items used.
    The following will contain only the 3 tags that you want:


           working-storage section.
           01 XML-DATA.
              03 XML-DATA-REC.
                 05 XML-DATA-DETAIL OCCURS 1 to 100 depending on ws-count.
                    07 XML-NUMBER PIC X(04).
                    07 XML-STRING PIC X(40).
           01 ws-count            pic 9(3)   value 3.
           01 ws-xml-count        pic 9(9).
           01 ws-xml-data         pic x(5000) value spaces.

           procedure division.
              move "TST1" to xml-number(1)
              move "TEST-STRING1" to xml-string(1)
              move "TST2" to xml-number(2)
              move "TEST-STRING2" to xml-string(2)
              move "TST3" to xml-number(3)
              move "TEST-STRING3" to xml-string(3)
              move 3 to ws-count

              XML GENERATE WS-XML-DATA FROM XML-DATA
                  COUNT IN WS-XML-COUNT
                  WITH XML-DECLARATION

             
  • Hi Chiris,

    what is the relation between XML-DATA and WS-XML-DATA? How can we define the size any formula?

  • Hi Chris,

    I do have one more query on where I can declare multiple array structure like two dimensional in same XML format.

    Please advise.

  • Hi Partha,

    In the example in this thread WS-XML-DATA will be the target field that will receive the generated XML upon completion. The field names under XML-DATA will be used as the tag names within the XML and the actual elementary fields like XML-NUMBER and XML-STRING will contain the data.

    The best answer is to copy and paste this code into a Visual COBOL project and run it and see what is generated.