我有以下要在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的值而不是第一个元素的值。
我想帮助实现这一目标。
答案 0 :(得分: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.