Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML PARSE Help

Status
Not open for further replies.

cworthi

Programmer
Jul 11, 2008
3
US
Hi,

I'm using the COBOL XML PARSER (XML PARSE stmt) for the first time and attempting to parse a document that has the same element tag <RqUID> in multiple places throughout the XML doc. For example...

<BankSvcRq>
<RqUID>123-456-789</RqUID>
<AcctInqRq>
<RqUID>454-123-987</RqUID>
</AcctInqRq>
</BankSvcRq>

Is there some mechanism/feature of the XML PARSER that will allow me to differentiate between the two occurences of RqUID? For example I would like to know that I'm dealing with <RqUID> of the <BankSvcRq> aggregate versus <RqUID> that forms part of the <AcctInqRq>. Or, will I have to manage this situation using good old COBOL logic?

Any help would be appreciated!
Thanks, Chris.
 
Hi cworthi,
AFAIK the COBOL XML Parser is a SAX Parser.
So you have "just" to implement an event handler for the SAX Parser - the section or paragraph specified in PROCESSING PROCEDURE of XML PARSE.
IMHO the easiest way to do it is implement it as a state machine.
 
Chris,
If the tag can exist under one or more parent tags, then you are going to have to do this manually yourself. There is no way (that I know of) that the PARSE statement can differentiate between the parents. What you will need to do is set a flag when the parents are recognised and then process the child element appropriately. Something similar to this might do
Code:
WHEN 'START-OF-ELEMENT'                                    
  MOVE XML-TEXT                TO XML-CURRENT-ELEMENT      
WHEN 'CONTENT-CHARACTERS'                                  
  EVALUATE XML-CURRENT-ELEMENT                             
    WHEN 'BankSvcRq'                                
      SET START-BANKSVC TO TRUE                            
    WHEN 'AcctInqRq'                                
      SET START-ACCTINQ TO TRUE                            
    WHEN 'RqUID'                                
       IF START-ACCTINQ
          DISPLAY 'RqUID found in AcctInqRq ' XML-TEXT
       ELSE
          IF START-BANKSVQ
             DISPLAY 'RqUID found in BankSvcRq' XML-TEXT
          ELSE
             DISPLAY 'RqUID found ' XML-TEXT
          END-IF
       END-IF
    WHEN 'END-OF-ELEMENT'              
       IF XML-TEXT = 'AcctInqRq'
          SET END-ACCTINQ TO TRUE
       END-IF
       IF XML-TEXT = 'BankSvcRq'
          SET END-BANKSVQ TO TRUE
       END-IF

The code above is obviosuly untested but should give you an idea of the way to go.

Hope this helps.

Marc
 
Thanks...I appreciate the suggestions/example. I'm deep enough into the coding of this program that it probably makes more sense for me to just add the extra logic using COBOL.

Regards, Chris.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top