Created On:  25th September 2012


If an XML document contains empty elements such as the RemoveThis element in:-

<?xml version="1.0"?>

then how can you remove then from the XML Document whne running COBOL under the .Net Framework.


One approach to doing this would be to apply a XSLT Transformation to the XML Document. Attached to this document is a demo showing how you can do this in managed .Net Visual COBOL The .Net Framework provides a number of classes for XML and allows a developer to apply XSLT transformations to XML.

The XSLT Transform being applied is:-

<xsl:sylesheet version="1.0" xmlns:xsl="">
  <xs:template match="@*|node()">
    <sl:if test=". != '' or ./@* != ''">
        <xsl:apply-templates select="@*|node()"/>

The Demo shows how to apply the technique to both an in-memory XML doc and also on a file containing XML. Supplied with the code is a batch file runit.bat that will build and run the demo.

In the code the definitons of class types has been declared using code as:-

       01  xmlxslt                     type System.Xml.Xsl.XslCompiledTransform.

This has been done to show the .Net namespace where the class exists. The code can be simplified with the ILUSING directive to specify the namespace:-

      $set ilusing(system.Xml.Xsl)


       01  xmlxslt                     type XslCompiledTransform.

With the ilusing directive the namespace can be ommitted from the code.