Pete.
--
I used to write COBOL; now I can do anything...
On Saturday, 23 June 2018 04:24:44 UTC+1, pete dashwood wrote:
Pete.
--
I used to write COBOL; now I can do anything...
Good to see that the Old Guard are still active (PECD, DD, Bill and others).
On Saturday, 23 June 2018 04:24:44 UTC+1, pete dashwood wrote:
Pete.
--
I used to write COBOL; now I can do anything...
Good to see that the Old Guard are still active (PECD, DD, Bill and others).
Over the last few weeks I have been deeply immersed in manipulating some reasonably complex (4 levels) XML streams.
I use LINQ to XML for this and it is very simple and works unfailingly.
For example, here's a snippet of an XML stream:
Here's the Root of the stream...
<?xml version="1.0" standalone="yes"?>
<!--PowerCOBOL Form description generated by PRIMA Tool XPCForm.-->
<Project ProjName="PCOBSample" ModuleName="PCOBSample">
<gridFlag>True</gridFlag>
<Form FormName="PCOBSampleForm">
<Text>A sample PowerCOBOL form</Text>
<Dimensions>
<TopY>00000</TopY>
<TopX>00074</TopX>
<Height>00524</Height>
<Width>00634</Width>
</Dimensions>
<Colors>
<Forecolor>DEFLT</Forecolor>
<Backcolor>FFFF00</Backcolor>
</Colors>
<!--The following controls were found on the PowerCOBOL
sheet...-->
<Controls>
<Control CtlName="CmFrame1">
...
( There are a series of "Control" entries that describe
the controls on a PowerCOBOL Form...)
[previous control here]
</Control>
<Control CtlName="CmTable1">
<CtlOrgName>CmTable1</CtlOrgName>
<Type>Table</Type>
<Text></Text>
<Dimensions>
<TopY>00057</TopY>
<TopX>00271</TopX>
<Height>00091</Height>
<Width>00255</Width>
</Dimensions>
<Colors>
<Forecolor>DEFLT</Forecolor>
... and so on...
Under some circumstances I want to replace the "Type" (currently
"Table"), with "DGV" representing a DataGridView. I also want to
create a new XML Element with the original Type in it.
But I only want to do this for a specific Control so it is necessary to
find the "CtlName" attribute that matches the one I want. (In this case
it is "CmTable1" and it is held in a string variable called "ctlName").
Here's the C# LINQ that does this...
// get the right control in the XML and add a new
// "originalType" element, then replace the existing
// Type with "DGV". Update the XML so it is reflected back
// in PC2NRel2 main stream.
try
{
var ctl = Form1.xml.Root.Descendants("Controls")
.Elements("Control")
.Where(x => x.Attribute("CtlName").Value.Trim() ==
ctlName.Trim())
.FirstOrDefault();
ctl.Element("Type")
.AddAfterSelf(new XElement("originalType", ctlType));
ctl.SetElementValue("Type", "DGV");
Form1.xml.Save(Form1.path2XMLfile,
SaveOptions.DisableFormatting);
}
catch (Exception xmlx)
{
string errmess = xmlx.Message; // for debugging
return false;
}
return true;
(It is actually 4 statements, within the try block, but Thunderbird
insists on breaking the lines so it looks like more. Each statement is terminated with a semi-colon... 1. get an object reference to the right control in the stream, 2. Create the new element with the old Type in
it, 3. Change the existing contents of the Type element to be "DGV", 4. replace the XML stream with the updated contents. )
After the code above runs, the stream is changed as...
...
<Control CtlName="CmTable1">
<CtlOrgName>CmTable1</CtlOrgName>
<Type>DGV</Type>
<originalType>Table</originalType>
<Text></Text>
<Dimensions>
<TopY>00057</TopY>
<TopX>00271</TopX>
<Height>00091</Height>
<Width>00255</Width>
</Dimensions>
<Colors>
<Forecolor>DEFLT</Forecolor>
<Backcolor>FFFF00</Backcolor>
</Colors>
<Properties>
<Parent>PCOBSampleForm</Parent>
<TabNDX>005</TabNDX>
<Enabled>TRUE</Enabled>
...
Although the code may seem unusual to people unfamiliar with LINQ and C#
it is really very easy once you acquire that skill. The above code took
less than 15 minutes to write and it worked perfectly first time it was run.
I remember some years back there was a lot of noise about adding XML
"verbs" to COBOL, and I was skeptical as to why you would, when there
were XML sub-system libraries available which could do the job. (I was
using them from COBOL before I switched to C#, where LINQ is part of the language - "Language INtegrated Queries")
I imagine the COBOL XML verbs would provide a similar extended
integrated facility that would be codable without the need to
specifically call special libraries?
If anyone here has actually used these extensions, would you give us
your impressions, please?
Pete.
--
I used to write COBOL; now I can do anything...
On Friday, June 22, 2018 at 11:24:44 PM UTC-4, pete dashwood wrote:
Over the last few weeks I have been deeply immersed in manipulating some
reasonably complex (4 levels) XML streams.
I use LINQ to XML for this and it is very simple and works unfailingly.
For example, here's a snippet of an XML stream:
Here's the Root of the stream...
<?xml version="1.0" standalone="yes"?>
<!--PowerCOBOL Form description generated by PRIMA Tool XPCForm.-->
<Project ProjName="PCOBSample" ModuleName="PCOBSample">
<gridFlag>True</gridFlag>
<Form FormName="PCOBSampleForm">
<Text>A sample PowerCOBOL form</Text>
<Dimensions>
<TopY>00000</TopY>
<TopX>00074</TopX>
<Height>00524</Height>
<Width>00634</Width>
</Dimensions>
<Colors>
<Forecolor>DEFLT</Forecolor>
<Backcolor>FFFF00</Backcolor>
</Colors>
<!--The following controls were found on the PowerCOBOL
sheet...-->
<Controls>
<Control CtlName="CmFrame1">
...
( There are a series of "Control" entries that describe
the controls on a PowerCOBOL Form...)
[previous control here]
</Control>
<Control CtlName="CmTable1">
<CtlOrgName>CmTable1</CtlOrgName>
<Type>Table</Type>
<Text></Text>
<Dimensions>
<TopY>00057</TopY>
<TopX>00271</TopX>
<Height>00091</Height>
<Width>00255</Width>
</Dimensions>
<Colors>
<Forecolor>DEFLT</Forecolor>
... and so on...
Under some circumstances I want to replace the "Type" (currently
"Table"), with "DGV" representing a DataGridView. I also want to
create a new XML Element with the original Type in it.
But I only want to do this for a specific Control so it is necessary to
find the "CtlName" attribute that matches the one I want. (In this case
it is "CmTable1" and it is held in a string variable called "ctlName").
Here's the C# LINQ that does this...
// get the right control in the XML and add a new
// "originalType" element, then replace the existing
// Type with "DGV". Update the XML so it is reflected back
// in PC2NRel2 main stream.
try
{
var ctl = Form1.xml.Root.Descendants("Controls")
.Elements("Control")
.Where(x => x.Attribute("CtlName").Value.Trim() ==
ctlName.Trim())
.FirstOrDefault();
ctl.Element("Type")
.AddAfterSelf(new XElement("originalType", ctlType));
ctl.SetElementValue("Type", "DGV");
Form1.xml.Save(Form1.path2XMLfile,
SaveOptions.DisableFormatting);
}
catch (Exception xmlx)
{
string errmess = xmlx.Message; // for debugging
return false;
}
return true;
(It is actually 4 statements, within the try block, but Thunderbird
insists on breaking the lines so it looks like more. Each statement is
terminated with a semi-colon... 1. get an object reference to the right
control in the stream, 2. Create the new element with the old Type in
it, 3. Change the existing contents of the Type element to be "DGV", 4.
replace the XML stream with the updated contents. )
After the code above runs, the stream is changed as...
...
<Control CtlName="CmTable1">
<CtlOrgName>CmTable1</CtlOrgName>
<Type>DGV</Type>
<originalType>Table</originalType>
<Text></Text>
<Dimensions>
<TopY>00057</TopY>
<TopX>00271</TopX>
<Height>00091</Height>
<Width>00255</Width>
</Dimensions>
<Colors>
<Forecolor>DEFLT</Forecolor>
<Backcolor>FFFF00</Backcolor>
</Colors>
<Properties>
<Parent>PCOBSampleForm</Parent>
<TabNDX>005</TabNDX>
<Enabled>TRUE</Enabled>
...
Although the code may seem unusual to people unfamiliar with LINQ and C#
it is really very easy once you acquire that skill. The above code took
less than 15 minutes to write and it worked perfectly first time it was run. >>
I remember some years back there was a lot of noise about adding XML
"verbs" to COBOL, and I was skeptical as to why you would, when there
were XML sub-system libraries available which could do the job. (I was
using them from COBOL before I switched to C#, where LINQ is part of the
language - "Language INtegrated Queries")
I imagine the COBOL XML verbs would provide a similar extended
integrated facility that would be codable without the need to
specifically call special libraries?
If anyone here has actually used these extensions, would you give us
your impressions, please?
Pete.
--
I used to write COBOL; now I can do anything...
Couldn't say much when this was originally posted, but GnuCOBOL will have XML GENERATE soon. Edward Hart is just finishing up a patch set.
https://sourceforge.net/p/open-cobol/patches/41/
Edward is following the spec from ISO/IEC TR 24716:2007
XML GENERATE x
FROM y
WITH XML-DECLARATION
NAME OF abc IS "ABCDEF", z IS "zeta"
TYPE OF z IS ATTRIBUTE
SUPPRESS WHEN SPACES
is one of the working fragments (fragments used during the work, that is)
No XML PARSE yet, but hey, we're volunteers. ;-) It won't take long, I don't imagine, now that Edward has completed the first half.
Although this is a bit of an answer into the future. GnuCOBOL programmers should be fairly steeped in COBOL XML within the next few months and I'll be posting samples and maybe some criticisms and/or praises as the case may be.
This engine is based on libxml2, and while the intent is for COBOL only syntax, the way GnuCOBOL works direct CALL to features in the library will be available whenever needed. (XSLT capable, for instance).
There have been no formal reviews yet, but I am getting the impression that Edward is impressed with the technical flexibility of the COBOL XML spec.
Have good, make good
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,030 |
Nodes: | 10 (0 / 10) |
Uptime: | 08:47:10 |
Calls: | 13,343 |
Files: | 186,574 |
D/L today: |
588 files (161M bytes) |
Messages: | 3,357,340 |