PDA

View Full Version : E4X : XML tweaking



MattCasters
01-19-2009, 06:50 PM
One of the lesser known features of Pentaho Data Integration 3.1 was the inclusion of E4X a.k.a EMCAScript for XML (http://en.wikipedia.org/wiki/E4X). 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”:

bar
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 :

bar
Our friends over at Mozilla have compiled an extensive set of explanations and examples on this page (https://developer.mozilla.org/index.php?title=En/Core_JavaScript_1.5_Guide/Processing_XML_with_E4X). Great job Mozilla!
Until next time,
Matt


More... (http://www.ibridge.be/?p=152)