XML Parse



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

XML Parse

Postby vishnusrini » Fri Sep 14, 2012 4:20 pm

Hi,

I have an input file which contain many start-of-element. Among all I found two element MorningstarCategory & MorningstarPrimaryBenchmark, just below of these both element i have their correcponding field 'NAME' & 'ID' (Even 'NAME & 'ID' is also one of the start-of element). how can I fetch the value from each 'ID' in XML parse COBOL, please guide me.

Input file - XML
~~~~~~~~
- <PackageBody>
- <MorningstarCategory>
<Name>Large Blend</Name>
<Id>$FOCA$LB$$</Id>

</MorningstarCategory>
- <MorningstarPrimaryBenchmark>
<Name>S&P 500 TR</Name>
<Id>XIUSA04G92</Id>

</MorningstarPrimaryBenchmark>


From the above input file, i want to fetch corresponding value of 'NAME' & 'ID'. Please guide me.
vishnusrini
 
Posts: 32
Joined: Wed Jul 07, 2010 2:55 pm
Location: India,bangalore
Has thanked: 0 time
Been thanked: 0 time

Re: XML Parse

 

Re: XML Parse

Postby dick scherrer » Fri Sep 14, 2012 9:24 pm

Hello,

I may be missing something, but i believe the answer to your "fetch" question is what you used for the subject of your title.

Using XML PARSE in the COBOL code should do what you want.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: XML Parse

Postby vishnusrini » Mon Sep 17, 2012 6:42 pm

Hi,

I am using XML PARSE only, but I want to know how we can take the CONTENT-CHARACTERS for 'ID' & 'NAME' for both START-OF-ELEMENT 'ID' & 'NAME' of its corresponding START-OF-ELEMENT MorningstarCategory & MorningstarPrimaryBenchmark.

Here my confusion, ID & NAME is START-OF-ELEMENT which comes in two place of input file with same name. As in both place this is START-OF-ELEMENT, so how could I differencate it and implement in XML PHRSE
vishnusrini
 
Posts: 32
Joined: Wed Jul 07, 2010 2:55 pm
Location: India,bangalore
Has thanked: 0 time
Been thanked: 0 time

Re: XML Parse

Postby Robert Sample » Mon Sep 17, 2012 6:57 pm

Use EVALUATE on XML-EVENT. When it is START-OF-ELEMENT, you will need IF or EVALUATE logic to determine which type of field it is and process appropriately. You'll probably need a flag in COBOL to set until you hit END-OF-ELEMENT to know when you're through with the particular field.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times

Re: XML Parse

Postby Ed Goodman » Mon Sep 17, 2012 7:18 pm

If I understand the PARSE command, you will set up a routine to roll through ALL of the tags. Each one will be passed into your routine in a special variable. The value of the data in the tag will be in another special variable. Based on the tag name, you can branch to a different handling routine to get the data value where you want it.

What's confusing me is that you say the XML is in a "file." Do you mean that the entire XML document is contained in a single record of a file? Or do you mean you have like 80-byte chunks per record?

Here is an example from IBM if you are dealing with a "chunked up" file: http://www.google.com/url?sa=t&rct=j&q= ... kQ&cad=rjt
Ed Goodman
 
Posts: 342
Joined: Thu Feb 24, 2011 12:05 am
Has thanked: 3 times
Been thanked: 17 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post