69
rated 0 times
[
71]
[
2]
/ answers: 1 / hits: 23183
/ 11 Years ago, tue, february 11, 2014, 12:00:00
Is there a possibility to change JSON data to XML in client side(Java sript or in Jquery).
More From » jquery
Is there a possibility to change JSON data to XML in client side(Java sript or in Jquery).
Try using JQuery http://api.jquery.com/jQuery.parseXML/
You can create an empty xml document like:
$.parseXML(<xml></xml>)
and then set properties on the document got from this.
An example to demonstrate:
var doc = $.parseXML(<xml/>)
var json = {key1: 1, key2: 2}
var xml = doc.getElementsByTagName(xml)[0]
var key, elem
for (key in json) {
if (json.hasOwnProperty(key)) {
elem = doc.createElement(key)
$(elem).text(json[key])
xml.appendChild(elem)
}
}
console.log(xml.outerHTML) // logs <xml><key1>1</key1><key2>2</key2></xml>