Simple XML Binding
As an alternative for the more flexible binding framework, there is also a simpler solution that can be used when there is a 1-to-1 coupling between the XML and the form.
The XML format is such that there is one XML element for each widget and the element gets the widget id as name. Exceptions from this are that the elements in a repeater get the name "item" and an attribute "position" with the position of the repeater child, instead of just a number (which is not allowed as element name). Childs of a MultiValueField are also embedded within an "item" element. If the Form widget does not have an id it gets the name "unknown".
An AggregateField can both be interpreted as one value and as several widgets. This ambiguity is resolved by choosing to emit the single value rather than the fields as XML. For population of the form both forms are however allowed.
The simple XML binding is implemented by the following class:
To load XML, you simply construct an XMLAdapter with a form instance as argument to the constructor. You can then load XML into the form simply by using the XMLAdapter as a ContentHandler for the XML parser, and save the XML by using the toSAX method on the XMLAdapter object.
In the flowscript CForm API, the form object has a getXML() method that returns an XMLAdapter instance. But more simply, there are also form.loadXML(uri) and form.saveXML(uri) methods.