0

我有以下要在 Cobol 中解析的 xml 结构。

<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>

正如你们所看到的,在 OD 标签之后有几个 OLD 标签。我想要做的是逐步阅读这个xml文件并以下列方式显示它的属性:

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             

但是当我执行程序时,od值不会改变。它返回以下值

1 1 2 3 1 4

我希望第二次出现返回第二个元素 OD 的值而不是第一个。

我想要一些帮助来实现这一目标。

4

1 回答 1

0

您可以使用“ xml parse ”语法:

   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.
于 2016-10-20T09:27:40.057 回答