One of the lesser known features of Pentaho Data Integration 3.1 was the inclusion of E4X a.k.a EMCAScript for XML. Up until recently I didn’t really have time to look more closely to the details behind it. Today someone asked how to set an attribute in an XML string using JavaScript. Well, this is how you do it…
Suppose we have the following piece of XML in a String field called “input”:
Now we want to set an attribute in with a certain id=5 :
var foo = new XML(input);
foo.@id = 5;
var result = request.toXMLString()
As you can see from the syntax, you need to construct a special XML object before you can work with it like we did.
By the way, the result is :
Our friends over at Mozilla have compiled an extensive set of explanations and examples on this page. Great job Mozilla!
Until next time,