Page 1 of 1

XML Parse

PostPosted: Fri Sep 14, 2012 4:20 pm
by vishnusrini
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.

Re: XML Parse

PostPosted: Fri Sep 14, 2012 9:24 pm
by dick scherrer
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.

Re: XML Parse

PostPosted: Mon Sep 17, 2012 6:42 pm
by vishnusrini
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

Re: XML Parse

PostPosted: Mon Sep 17, 2012 6:57 pm
by Robert Sample
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.

Re: XML Parse

PostPosted: Mon Sep 17, 2012 7:18 pm
by Ed Goodman
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