0

I have the following xml-structure that I want to parse in Cobol.

<LDO>
  <OD>1</OD>     //OD 1'st occurrence
  <OLD>1</OLD>    //OLD 1'st occurrence
  <OLD>2</OLD>    //OLD 2'nd occurrence
  <OLD>3</OLD>    //OLD 3'rd occurrence
  <OD>2</OD>     //OD 2'nd occurrence
  <OLD>4</OLD>    //OLD 4'th occurrence
</LDO>

As you guys can see there is several OLD tags after an OD tag. What I want to do is reading this xml file step by step and display it's attributes in the following way:

1 1 2 3 2 4

           READ xml-stream.
       START xml-stream KEY IS OD.

       *>check status

       START xml-stream KEY IS OLD.
       *> check stream status                 

       PERFORM UNTIL EXIT
            READ xml-stream next key is
            old
            IF  stream-status = -7
               EXIT PERFORM
            END-IF
            *> check stream status less than 0
            display od-value
            display old-value             

But the od-value doesn't change when i excecute the program. It return the following values

1 1 2 3 1 4

I want that the second occurrence to return the value of the second element OD not the first one.

I would like some help to achieve this.

Mnemonics
  • 679
  • 1
  • 10
  • 26

1 Answers1

0

You could use the "xml parse" syntax:

   program-id. xp.
   01 xdoc pic x(1024) value
   " <LDO>" &
    "  <OD>1</OD>" &
    "  <OLD>1</OLD>" &
    "  <OLD>2</OLD>" &
    "  <OLD>3</OLD>" &
    "  <OD>2</OD>" &
    "  <OLD>4</OLD>" &
    "</LDO>".

   procedure division.
        Xml parse xdoc processing procedure p
            ON EXCEPTION
              display 'XML document error 'XML-CODE
          NOT ON EXCEPTION
              display 'XML document successfully parsed'
          END-XML
        goback.

         p.
            Evaluate xml-event
                When 'START-OF-ELEMENT'
                When 'CONTENT-CHARACTERS'
                  exhibit named xml-text
                When 'CONTENT-CHARACTER'
                  exhibit named xml-text
                When 'END-OF-ELEMENT'
                  exhibit named xml-event
                When other
                  exhibit named xml-event
        End-evaluate
        .


   end program xp.
Stephen Gennard
  • 1,910
  • 16
  • 21