We are proud to announce the immediate availability of the XML-Plugin version 1.0.1.
The plugin allows Servoy developers to create, manipulate and read XML documents directly from within Servoy. The plugin allows you for example to
- Exchange data in a state-of-the-art format
- Subscribe to RSS feeds
- Display XML content in HTML without further coding (using a style sheet)
- Directly archive Servoy records in XML format
- Create MS Office (or OpenOffice) documents from templates (Office 2003 or greater)
- Import FileMaker XML exported data
Here is a (short) overview of the plugin’s classes and their functionality
XML-Plugin
- create XMLDocument from file, URL, XML text, a Servoy record or foundset (possibly including relations)
- create XMLElement using name or directly from a Servoy record
- create XMLAttribute with name and value (optionally including namespace)
- create XMLNamespace with prefix and URI
- create RecordFormatter
XMLDocument - get/set doctype
- get/set encoding
- add/get comments
- add/get elements
- add namespace declarations
- get as (pretty formatted) text
- get elements by XPath expression
- get elements by their name
- validate
- write to file
- transform using XSL
XMLElement - get/set name
- get/set text (value)
- get/set namespace
- add/get attributes
- add/get/remove additional namespace declarations
- add/get/remove children (optionally by name)
- get descendants
XMLAttribute - get/set name
- get/set value
- detach from parent
- get parent
XMLNamespace
- get/set prefix and URI
RecordFormatter
The plugin can also be used to “archive” Servoy records (including related data) in XML format. If doing that, the data type has to be preserved, because after all XML is only text. You can create an XMLDocument directly from a Servoy record using a distinct format, that will include formatting information so data can be extracted using the original datatype. This is what the RecordFormatter does: convert a record to String and vice versa using formatting patterns. Here is an example that will write a complete foundset including all related data and reverse-create the record data with the original data type preserved with just a few calls:
// Creating an XML document from the foundset using all defined relations is a simple as
var vXml = plugins.XML.XMLDocument(foundset, allrelations);
// Now get the original data back out of the XML
// First, get the format used when converting data to text
var vFormatter = vXml.getFormatterElement();
// Now get all elements representing each record from the foundset
var vRecordElements = vXml.getRecordElements();
// Loop over all records found
for ( var i = 0 ; i < vRecordElements.length ; i++ )
{
// Get an element representing record i from the foundset
var vRecordElement = vRecordElements[i];
// Get the record's data as object[columnName][data]
var vRecordData = vRecordElement.getRecordData(vFormatter);
// Get all relations found for this record as String[relationName][tableName]
var vAllRelations = vRecordElement.getRelationsFromRecord();
// Loop over all relations attached to this record
for ( var j = 0 ; j < vAllRelations.length ; j++ )
{
// Get all record elements for relation j
var vRelatedRecordElements = vRecordElement.getRecordsFromRelation(vAllRelations[j][0]);
// Loop over all related records to get each single record for relation j
for ( var k = 0 ; k < vRelatedRecordElements.length ; k++ )
{
// Get the related record's data as object[columnName][data]
var vRelatedRecordData = vRelatedRecordElements[i].getRecordData(vFormatter);
}
}
}
The plugin can be found on www.servoy-plugins.de. You can buy a license from the shop or ask for a demo version (runs for 30 minutes after each start of Servoy) by sending a mail to plugins@maison-partner.de.