Call Us Today! 877.742.2583

Page tree
Skip to end of metadata
Go to start of metadata


A list of examples of JavaScript XML in FreeSWITCH.

 Click here to expand Table of Contents


The new V8 module relies on XML support built into FS, since Google V8 doesn't have this built-in like Spidermonkey.

var xmldata = new XML("<mydata><item>this is my data</item><item>this is also my data</item></mydata>");
for each (item in xmldata.item) {
    console_log("ITEM: " + item + "\n");
JS XML examples
// Tell JS we wan't to load the XML class features.

// Load and parse an XML string.
var xml = new XML('<xml><test>TestData</test><test>TestData 2<test2>test</test2></test></xml>');

// Get the first child named 'test'
var child = xml.getChild('test');

if (child) {
    consoleLog('info', 'XML child name: ' + + ', data: ' +;

// Get next child of the same name and same level
var nextChild =;

if (nextChild) {
    consoleLog('info', 'XML child name: ' + + ', data: ' +;

// Create a new child
var newChild = xml.addChild('NewTest');

// Set some data to it = 'new data';

// Set an attribute
newChild.setAttribute('firstattr', 'myvalue');

// Print the attribute
consoleLog('info', 'XML newChild attrbute firstattr: ' + newChild.getAttribute('firstattr'));

// Remove the first child 'test'

// Log the entire XML
consoleLog('info', 'Full XML ::\n' + xml.serialize());