View previous topic :: View next topic
|
Author |
Message |
rss0213
New User
Joined: 20 Jan 2010 Posts: 26 Location: Alabama
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
If this is just beginning, suggest the element names be made unique. |
|
Back to top |
|
|
rss0213
New User
Joined: 20 Jan 2010 Posts: 26 Location: Alabama
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
rss0213
New User
Joined: 20 Jan 2010 Posts: 26 Location: Alabama
|
|
|
|
That's the approach I'm taking. Thanks
If anyone else knows how to handle this, please advise. Thanks |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Ed Goodman
Active Member
Joined: 08 Jun 2011 Posts: 556 Location: USA
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Guess who does not "do" XML . . .
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 |
|
Back to top |
|
|
Ed Goodman
Active Member
Joined: 08 Jun 2011 Posts: 556 Location: USA
|
|
|
|
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 |
|
|
rss0213
New User
Joined: 20 Jan 2010 Posts: 26 Location: Alabama
|
|
|
|
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 |
|
|
|