XML

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

Version 3.x

Basic Usage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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