Developing with the SDK > Using and Writing Data Models > Handling XML Data Files in Java

If you have existing data in an XML format, there is support in the class ilog.views.sdm.IlvSDMEngine for reading, writing and transforming it.

Reading Data

There are several ways available to read an XML file:

Writing Data

There are several ways available to write the contents of the data model to an XML file:

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:

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 web site (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 ILOG 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 ilog.views.sdm.util.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";
}