HI -
I have file that contains 1 record but the length of data can be from 2 chars to 700,000 chars. I want to access such file in RM/COBOL program, ran via shell.
Neither FD section approach nor sending via LINKAGE section is working. Using XML IMPORT FUNCTION. Is there any other oway to pass the data. Something like reading file in shell, pass address of data to cobol program, and Cobol access via address if possible. [Looking for utilityC CRG or DARG].
#linuxcobol#RM/COBOLDear Swapnil,
Is there any structure to the data? You mention XML...does the data have XML markup?
Or is this just a BLOB (binary large object)?
Dear Swapnil,
Is there any structure to the data? You mention XML...does the data have XML markup?
Or is this just a BLOB (binary large object)?
It is json document .. with Multiple occurrences
It is json document .. with Multiple occurrences
I use a fairly simple PHP script to translate JSON to XML. Here it is...
<?php
$file = 'php://stdin';
$file = file_get_contents($file);
$array = json_decode($file, true);
// print_r($array);
$dom = new DOMDocument('1.0', 'utf-8');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = false;
$root = $dom->createElement('root');
$dom->appendChild($root);
array2xml($array, $root, $dom);
echo $dom->saveXML();
function array2xml($array, $node, &$dom, $defaultName = 'rootItem')
{
foreach($array as $key => $value)
{
if(preg_match("/^[0-9]/", $key))
// $key = "node-{$key}";
$key = $defaultName;
$key = strtolower(preg_replace("/[^a-z0-9_\\-]+/i", '', $key));
if($key==='')
$key = '_';
$a = $dom->createElement($key);
$node->appendChild($a);
if(!is_array($value))
$a->appendChild($dom->createTextNode($value));
else {
$newDefault = (substr($key,-1) == 's') ? substr($key,0,-1) : ($key . 'Item');
array2xml($value, $a, $dom, $newDefault);
}
}
}
?>
We had a major vendor shift from XML to JSON. Documents were complicated. This script works.
Then, you create XSLT to import the output from the script.
Good luck!
Tom