RISE to Bloome Software
Log In    
Home
RISE
Marshal
Download
 
 
r2bsoftware.se r2bsoftware.se
 
 
 
Click to hide navigation tree

Code generators

For easy reading and writing of exported XML, the Marshal Editor provides built-in c# and Java code generators. Use them when writing export post-processors for transformation purposes or when loading data into external systems, such as a data warehouse or a long-term archive. 

The source code generators assure consistent reading and writing of exported XML files. This includes safeguarding the structure of the files as well as the data types of elements and attributes. The generated code makes use of the standard file system, XML, XPath and type conversion utilities of each platform, respectively. 

The Marshal Editor also provides an XSD code generator, generating a schema for your exported XML files.

To generate code for a Marshal model project, simply open your Marshal model a push the toolbar button for the type of of code you need. The generated code is displayed in the Marshal code generator dialog, shown below. Marshal generates a single file containing a class structure mimicking the structure of the corresponding XML export files. Simply, save, or copy-and-paste, this source code into your development project in, for instance, Visual Studio or Eclipse.


In this example we generate code for an export model, exporting sites and content from a content management system. The image below shows an XML export opened using XML Notepad.

Sample export in XMLNotepad

The code snippets below shows how to make use of the generated code when operating on Marshal exports.

How to use the source code

These sample snippets shows how to load, edit and save an export file in c# and Java respectively.

First the export is loaded using MXmlLoad/mXmlLoad and all site names are listed. Then a new site, with an articles container, having a single article is added using MXmlCreate/mXmlCreate. The creation utility requires all mandatory properties to be specified. Once the article is created its content is set using the set operator content/setContent. Finally the modified information structure is saved by overwriting the original file using MXmlSave/mXmlSave.

The c# sample code is written in Visual Studio and requires that the directive "using com.test.cms;" is present in the source file.

The Java code is an excerpt from an application written in Eclipse. It requires the "import com.test.cms.Sites;" directive to run.
For both languages, running the sample code will result in an export file modified according to:


How to load an indexed export

Marshal supports exporting to a file structure rather than to a single XML file. In this case, each export results in an XML index file with references to the individual XML files. The Marshal Editor generates source code for the index file as well. For details on how to setup multi-file export see the Export Folder Naming property in The Root Node.

We continue our example by modifying the model so that it exports multiple files, containing a single Site element. The code generators will now generate an extra top level class, SiteIndex. For c# this class is added to Site.cs file alongside the Site class. For Java, where files with multiple classes aren't allowed, an extra file SiteIndex.java is generated.


The below sample code shows how to use the index file to find, and open, the export files in c# and Java respectively.
Note that for the Java code to run you need to import both classes, i.e. add the "import com.test.cms.*;" directive.

How to use the XSD

Marshal generates XSD (XML Schema Document) files describing the schema of the resulting XML files.


The left-hand image shows the XSD, generated as part of this example, opened in Visual Studio. 

The main use case for XSD is to serve as part of the reference documentation for XML files. Typically, put the XSD in the specifications or store it in relation to the XML content.

It is also possible to use an XSD for automated validation of XML files.