The Javascript XML Transform builder will transform an XML document using server side javascript and E4X notation. This provides a more natural and intuitive way of manipulating XML, and an easy way to test the transformation in the designer without having to execute the model. The builder is an alternative to using java code and the IXml API to transform XML documents.
Here are some reasons why this is my preferred way of handling XML in WEF
-
Javascript is easier to work with than java for many web developers. If you've worked with HTML then odds are you're familiar with javascript, now you can use those skills instead of learning java.
-
The builder exposes the XML as javascript variables so the developer can focus on the business logic at hand instead of the details of the IXml java API.
Take for example the following simple XML:
<contacts>
<person>
<name>Carl</name>
<car>Nissan</car>
</person>
<person>
<name>Subash</name>
<car>Honda</car>
</person>
</contacts>
Javascript with E4X notation can then refer to elements like this:
contacts.person[0].name; // returns 'Carl'
XML can be created with a script:
function main(){
var rowset = <rowset/>;
for(var x=0; x < contacts.person.length(); x++){
rowset.row[x] = contacts.person[x].name + " drives a " + contacts.person[x].car;
}
return rowset;
}
main();
which produces this output:
<rowset>
<row>Carl drives a Nissan</row>
<row>Subash drives a Honda</row>
</rowset>
Check out my website for a video demonstration of this builder.