• COBOL XML extensions

    From pete dashwood@dashwood@enternet.co.nz to comp.lang.cobol on Sat Jun 23 15:24:39 2018
    From Newsgroup: comp.lang.cobol

    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...
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Alistair Maclean@alistair.j.l.maclean@gmail.com to comp.lang.cobol on Mon Jun 25 15:30:15 2018
    From Newsgroup: comp.lang.cobol

    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). --- Synchronet 3.20a-Linux NewsLink 1.114
  • From pete dashwood@dashwood@enternet.co.nz to comp.lang.cobol on Tue Jun 26 18:14:20 2018
    From Newsgroup: comp.lang.cobol

    On 26/06/2018 10:30 AM, Alistair Maclean wrote:
    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).

    Speaking for myself... "only just..." :-)

    I see this newsgroup as beyond rubies because it is a last bastion of unmoderated, unedited, free speech and that alone makes it worth a visit.

    I retain an interest in things COBOL as well, so I guess that also moves
    me to come here.

    But the days when people came here to get help with using COBOL are
    pretty much over... These days it is much quicker to run a GOOGLE search
    for what you want to know, than to run the gauntlet here.

    Nevertheless, there is something "comforting" about discussing stuff
    with a group of people who all share an interest in an ancient computer programming language and knowing that the people you are talking to have worked through many of the same problems as yourself.

    I intend to continue posting here as long as I can see and type (and
    think... :-)) but I understand that won't be indefinitely... :-)

    Nice to see you dropped by, Alistair.

    Pete.
    --
    I used to write COBOL; now I can do anything...
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From docdwarf@docdwarf@panix.com () to comp.lang.cobol on Thu Jun 28 00:01:56 2018
    From Newsgroup: comp.lang.cobol

    In article <e70b50a7-dd2e-4e44-a84f-f318f6d42e58@googlegroups.com>,
    Alistair Maclean <alistair.j.l.maclean@gmail.com> wrote:
    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).

    zzzZZZzzzz... eh? It has been a while, Mr Maclean, and - believe it or otherwise - a thought of you came to my mind a... brief bit back, when I
    was doing... something or other.

    Me, I toddle along, about the same... a bit less tolerant of those asking
    me to Do Their Jobs or Homework, slightly more stooped of shoulder and a
    bit more emphatically broken of wind... as I said, about the same. Just to shake things up a bit I arranged this past November to take a course of
    study at a local university... but on 10 April they informed me that the classes due to start 1 June were postponed for a year.

    Things go well with you, I trust?

    DD
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From bwtiffin@bwtiffin@gmail.com to comp.lang.cobol on Mon Aug 13 13:19:10 2018
    From Newsgroup: comp.lang.cobol

    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
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From pete dashwood@dashwood@enternet.co.nz to comp.lang.cobol on Tue Aug 14 10:45:08 2018
    From Newsgroup: comp.lang.cobol

    On 14/08/2018 8:19 AM, bwtiffin@gmail.com wrote:
    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)

    A fine, but important distinction... :-)


    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.

    I have noticed a slow rise in the use of XML over the last few years and
    I think it is important. The new tools I am currently writing use XML
    under the covers and it is very good.

    For me, being able to access and build it with LINQ is just the icing on
    the cake; LINQ means there is ONE syntax for accessing anything that is searchable: XML, RDBs, Dictionaries, Lists, and Collections in memory...
    I LOVE it! (I couldn't go back to SQL now and see it as obsolete...)

    Nevertheless the COBOL sample does look good and I wish you well with
    your endeavours, Brian.



    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.


    I haven't seen it myself, but I'll look forward to seeing some samples
    when people get to use it.

    Have good, make good


    Pete.
    --
    I used to write COBOL; now I can do anything...
    --- Synchronet 3.20a-Linux NewsLink 1.114