XML

XML object is used to transfrom from JSON to XML and vice versa.

Version 4.x

Basic Usage

var xml = require("utils/v4/xml");
var response = require("http/v4/response");

var jsonInput = {
    firstName: "John",
    lastName: "Doe",
    bio: {
        age: 24,
        sex: "male"
    }
};

var xmlInput = 
"<person>" +
    "<firstName>John</firstName>" +
    "<lastName>Doe</lastName>" + 
    "<bio>" + 
        "<age>24</age>" +
        "<sex>male</sex>" +
    "</bio>" +
"</person>";

response.println(xml.fromJson(JSON.stringify(jsonInput)));
response.println(xml.toJson(xmlInput));

response.flush();
response.close();

Definition

Functions


Function Description Returns
fromJson(json) Converts a JSON to a XML string string
toJson(xml) Converts a XML to JSON string string

Compatibility

Rhino Nashorn V8 Graal

Version 3.x

Basic Usage

var xml = require("utils/v3/xml");
var response = require("http/v3/response");

var jsonInput = {
    firstName: "John",
    lastName: "Doe",
    bio: {
        age: 24,
        sex: "male"
    }
};

var xmlInput = 
"<person>" +
    "<firstName>John</firstName>" +
    "<lastName>Doe</lastName>" + 
    "<bio>" + 
        "<age>24</age>" +
        "<sex>male</sex>" +
    "</bio>" +
"</person>";

response.println(xml.fromJson(JSON.stringify(jsonInput)));
response.println(xml.toJson(xmlInput));

response.flush();
response.close();

Definition

Functions


Function Description Returns
fromJson(json) Converts a JSON to a XML string string
toJson(xml) Converts a XML to JSON string string

Compatibility

Rhino Nashorn V8

Version 2.x

Basic Usage

var xml = require('utils/xml');
var response = require('net/http/response');

var jsonInput = {
	'firstName': 'John',
	'lastName': 'Doe',
	'bio': {
		'age': 24,
		'sex': 'male'
	}
};

var xmlInput = 
	"<firstName>John</firstName>" +
	"<lastName>Doe</lastName>" + 
	"<bio>" + 
	"<age>24</age>" +
	"<sex>male</sex>" +
	"</bio>";

response.println(xml.fromJson(jsonInput));
response.println(xml.toJson(xmlInput));

response.flush();
response.close();

Definition

Functions


Function Description Returns
fromJson(json) Converts a JSON to a XML string string
toJson(xml) Converts a XML to JSON string string

Compatibility

Rhino Nashorn V8

Edit