Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
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

 Answers
9

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>

[#72598] Monday, February 10, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
guadalupec

Total Points: 610
Total Questions: 91
Total Answers: 91

Location: Guernsey
Member since Tue, Jul 6, 2021
3 Years ago
;