Reading and writing custom XML formats

It is possible to read and write data in any XML format. To do this, you have two solutions:
  • Transform the XML format to the Rogue Wave® JViews Diagrammer SDM format using XSLT transformations
  • Write a subclass of the utility class IlvXMLConnector

Using XSLT

XSLT is the simplest solution for reading and writing custom XML formats, because it requires no Java™ coding. This solution is easier to apply when the structure of the custom XML format is relatively close to the required structure.
For documentation and resources on XSLT, see the W3C website (http://www.w3c.org). Proceed as follows:
  1. Write two XSLT files: one that will convert an XML document from the custom format to the SDM format (for reading), and another one that will convert a document from the SDM format to the custom format (for writing).
  2. Create an instance of the class IlvXSLConnector (a subclass of IlvXMLConnector), specifying the two XSLT files. To do this through the style sheet add a rule with the following structure:
    XMLConnector{
        class : "ilog.views.sdm.util.IlvXSLConnector";
        inputTemplates : "url(custom2sdm.xsl)";
        outputTemplates : "url(sdm2custom.xsl)";
    }
    
    where the two XSLT files are custom2sdm.xsl (for reading), and sdm2custom.xsl for writing.
Note that the two XSLT files must be written so that no information is lost, that is, the two transformations should be the exact inverse of one another. If the custom XML format contains information that is not useful for Rogue Wave JViews Diagrammer purposes or that cannot be translated easily, this information can be stored as metadata (see Metadata in the XML data file in Using the Designer).
It is possible to specify only one transformation. For example, you may specify only the input templates file if you read only custom XML files, but never modify and write them back.

Subclassing the XML connector

There may be cases when you will not be able to write XSL transformations between the custom XML format and the SDM format, usually because the structures are too different and the XSLT language does not allow you to implement the transformation.
In such cases, proceed as follows:
  1. Write a subclass of IlvXMLConnector.
  2. Create an instance of your custom XML connector in the style sheet, by writing a rule with the following structure:
    XMLConnector{
        class : "my.package.MyConnector";
    }