Today we released the first public beta of our XML plugin.
The XML plugin allows you to do things like:
- Create an XML document (object) from an XML file, a URL or from a Servoy record or foundset. You can also start with an empty XML document and add elements yourself.
- Parse XML content inside Servoy
- Support for namespaces, comments and attributes
- Includes a recordFormatter class that will properly encode a Servoy record for XML use (formats dates, numbers and media content). The recordFormatter can also re-create an array from XML data, where the correct data type will be returned (so for example a base64 encoded media content inside the XML will be returned as a byte array)
- Support for xsl transformation that allows you to format XML content using a style sheet and properly output the XML in HTML
Besides the possibility to create and parse any XML document, the plugin can also create XML from Servoy records and foundsets including related data if needed. A simple call like
var vRelations = new Array('relation1', 'relation2');
var vFoundsetXml = plugins.XML.XMLDocument(foundset, vRelations);
can create an XML document like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<table name="data">
<formatting>
<DATE>dd.MM.yyyy</DATE>
<DATETIME>dd.MM.yyyy HH:mm</DATETIME>
<DATETIMESECONDS>dd.MM.yyyy HH:mm:ss</DATETIMESECONDS>
<NUMBER>#,##0.##</NUMBER>
<INTEGER>#,###</INTEGER>
<MEDIA>Base64</MEDIA>
</formatting>
<data>
<record dataid="62">
<data>
<text_field type="TEXT">This is just plain text.</text_field>
<number_field type="NUMBER">23,45</number_field>
<dataid type="INTEGER">62</dataid>
<date_field type="DATE">20.05.2006</date_field>
<integer_field type="INTEGER">1</integer_field>
</data>
<relation name="relation1" table="related_data">
<record related_dataid="1">
<data>
<text_field type="TEXT">some text</text_field>
<number_field type="NUMBER">24,4</number_field>
<dataid type="INTEGER">62</dataid>
<related_dataid type="INTEGER">1</related_dataid>
<date_field type="DATE">20.05.2006</date_field>
</data>
</record>
<record related_dataid="2">
<data>
<text_field type="TEXT">some more text</text_field>
<number_field type="NUMBER">19,8</number_field>
<dataid type="INTEGER">62</dataid>
<related_dataid type="INTEGER">2</related_dataid>
<date_field type="DATE">11.05.2006</date_field>
</data>
</record>
</relation>
</record>
</data>
</table>
We use this for example to archive deleted records. When those records have to be recreated, the plugin offers a functionality that allows you the provide the above XML and get an Array with all included data transformed to the data type the field has. This can be done as easy as
// Create an XML document from XML data
var vXml = plugins.XML.XMLDocument(xml_data);
// Get the record element(s)
var vRecords = vXml.getRecordElements();
for ( var i = 0 ; i < vRecords.length ; i++ )
{
// Get the i-th record element
var vSingleRecord = vRecords[i];
// Let the RecordFormatter re-create an object array, where the single fields are returned according to their type
var vRecordObject = vRecordFormatter.getRecordObject(vSingleRecord, vFormatter);
}
the vRecordObject is a two-dimensional array that contains colum name and the field content either as Text, Integer, Number, Date or Byte Array.
As long as the plugin is in beta testing, please contact me by email if you want to test it.