Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to handle XML subelements withe the same element names

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
rss0213

New User


Joined: 20 Jan 2010
Posts: 26
Location: Alabama

PostPosted: Mon Jan 14, 2013 7:47 am    Post subject: How to handle XML subelements withe the same element names
Reply with quote

Hi. I have an XML schema I'm trying to parse that contains subelements with the same element name. For example:

Code:
/PaymentSegment/PaymentAmount/Currency
/PaymentSegment/PaymentAmount/Amount


... and ...

Code:
/PaymentSegment/InstructAmount/Currency
/PaymentSegment/InstructAmount/Amount


How do I distinguish between the two Currency and Amount fields for my MOVE statements?
Back to top
View user's profile Send private message

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Jan 14, 2013 8:19 am    Post subject:
Reply with quote

Hello,

If this is just beginning, suggest the element names be made unique.
Back to top
View user's profile Send private message
rss0213

New User


Joined: 20 Jan 2010
Posts: 26
Location: Alabama

PostPosted: Mon Jan 14, 2013 9:24 am    Post subject:
Reply with quote

The schema was created by a vendor, and it's used in the messages their application produces. Is there a way to distinguish them?
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Jan 14, 2013 8:57 pm    Post subject:
Reply with quote

Hello,

One way would be to pre-process the messages and make sure the names are unique. Surely not too attractive.

If your organization is paying for this data/process, i suspect your management could influnce what was delivered - even if this was agreed on previously. . .

If this were my issue, i'd ask the vendor how other clients have dealt with the duplicate names.
Back to top
View user's profile Send private message
rss0213

New User


Joined: 20 Jan 2010
Posts: 26
Location: Alabama

PostPosted: Mon Jan 14, 2013 9:32 pm    Post subject:
Reply with quote

That's the approach I'm taking. Thanks

If anyone else knows how to handle this, please advise. Thanks
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7905
Location: Bellevue, IA

PostPosted: Mon Jan 14, 2013 10:07 pm    Post subject:
Reply with quote

The only way I can think of to handle this would be to set a flag in your COBOL program to indicate which branch of XML your program is currently processing; you would then know from the flag whether you have a PaymentAmount or InsttructAmount.
Back to top
View user's profile Send private message
Ed Goodman

Active Member


Joined: 08 Jun 2011
Posts: 556
Location: USA

PostPosted: Tue Jan 15, 2013 7:12 pm    Post subject:
Reply with quote

There is an 'END-OF-ELEMENT' event that throws when you get to the end of a tag. You should keep track of those and then you would know the level you are in.

The idea of making XML have unique names if not going to fly. It's got a hierarchy for exactly that reason.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Jan 15, 2013 8:03 pm    Post subject:
Reply with quote

Hello,

Guess who does not "do" XML . . . icon_redface.gif

Is there a Small document that explains why non-unique names woud be better than unique names? Or just from one's own knowledge/experience.

Most likely, i'll not be involved with XML directly/technically, but it is mentioned more these days than 5 years ago . . .

So i'll starting picking up bits here and there icon_cool.gif
Back to top
View user's profile Send private message
Ed Goodman

Active Member


Joined: 08 Jun 2011
Posts: 556
Location: USA

PostPosted: Tue Jan 15, 2013 9:40 pm    Post subject:
Reply with quote

http://www.w3schools.com/xml/xml_whatis.asp

It may be easiest to think of it as an IMS database.

There is a root, and different 'elements' hang under that, then each of those can have its own children ad infinitum.

So,
Code:
<case>
   <customer>
      <demographics>
          <name>Ed Goodman</name>
          <age>106</age>
      </demographics>
      <accounts>
          <checking>
               <account_num>123456789</account_num>
          </checking>
          <savings>
               <account_num>987654321</account_num>
          </savings>
      </accounts>
   </customer>
   <customer>
      <demographics>
          <name>Annie Goodman</name>
          <age>29</age>
      </demographics>
      <accounts>
          <checking>
               <account_num>123456789</account_num>
          </checking>
          <savings>
               <account_num>987654321</account_num>
          </savings>
      </accounts>
   </customer>
<case>
 

Notice how the 'account_num' tag is perfectly valid in both places? The normal reaction of relational DB folks is to try for account_num_checking and account_num_savings, but that's not really what you are representing. There might be any number of checking accounts, including none. Trying to do account_num_checking_01 .. 99 just makes things weird, and it wastes space.
Back to top
View user's profile Send private message
rss0213

New User


Joined: 20 Jan 2010
Posts: 26
Location: Alabama

PostPosted: Wed Jan 16, 2013 6:22 am    Post subject:
Reply with quote

I'm taking Mr Sample's approach. I set a flag that tells me which parent element I'm processing. I also explicitly turn OFF the other parent elements' flags that might have this same sub-element name. So, here's the code:

Code:
05  WS-FLAGS.
    10  WS-PMT-AMT-ELE           PIC  X(01)  VALUE 'N'.
        88  PMT-AMT-ELE                      VALUE 'Y'.
    10  WS-INS-AMT-ELE           PIC  X(01)  VALUE 'N'.
        88  INS-AMT-ELE                      VALUE 'Y'.

WHEN 'CONTENT-CHARACTERS'
    EVALUATE CURRENT-ELEMENT
        WHEN 'PAYMENTAMOUNT'
            MOVE 'Y'              TO  WS-PMT-AMT-ELE
            MOVE 'N'              TO  WS-INS-AMT-ELE
        WHEN 'INSTRUCTAMOUNT'
            MOVE 'Y'              TO  WS-INS-AMT-ELE
            MOVE 'N'              TO  WS-PMT-AMT-ELE
        WHEN 'CURRENCY'
            IF  PMT-AMT-ELE
                MOVE CURRENT-ELEMENT TO  PMT-AMT-CURRENCY
            ELSE
            IF  INS-AMT-ELE
                MOVE CURRENT-ELEMENT TO  INS-AMT-CURRENCY
            END-IF
            END-IF
        WHEN 'AMOUNT'
            IF  PMT-AMT-ELE
                MOVE CURRENT-ELEMENT TO  PMT-AMT-AMOUNT
            ELSE
            IF  INS-AMT-ELE
                MOVE CURRENT-ELEMENT TO  INS-AMT-AMOUNT
            END-IF
            END-IF
            MOVE CURRENT-ELEMENT  TO  PMT-AMT-AMOUNT


It turns out I have lots of these with this vendor's XML schema. Thanks for the help everyone!
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts hot to get details when "EXEC CI... Andi1982 CICS 11 Tue Sep 20, 2016 5:01 pm
No new posts Variable for cursor names ravikumar15 DB2 5 Sun Jul 17, 2016 7:08 am
No new posts Using Field names in FILEAID Batch CO... Atul Banke Compuware & Other Tools 2 Wed Jun 29, 2016 9:54 pm
No new posts SE37 while adding element to endevor kalyan.v CA Products 5 Mon Apr 25, 2016 6:05 pm
No new posts How to handle AISS abend ? robin ma 2015 CICS 1 Mon Nov 09, 2015 1:47 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us