-2

I am converting JSON Values to XML. Instead of getting JSON properties as elements of XML I am getting &quot;title&quot;:&quot;source&quot;. The output I wanted is <title>source</title>. What is the mistake I am doing? I am writing this code in JavaScript function.

I am using x2js plugin for conversion and I have included it using script tag.

My code to convert dynatree to JSON and JSON to XML is:

var x2js = new X2JS();

var tree = $("#source").dynatree("getTree").toDict();
alert("  tree:"+tree);
var jsonObject = JSON.stringify(tree);//dynatree to JSON
alert(" jsonObject :"+jsonObject);       
var xmlAsStr = x2js.json2xml_str( jsonObject );//JSON to XML
alert("xml "+xmlAsStr);
Biffen
  • 6,249
  • 6
  • 28
  • 36
  • Why is this tagged Java?! – Biffen Apr 08 '15 at 10:56
  • Ya i know that ..first of all do you have an answer for this question? i need to use this data in java file..solution in either java or javascript both works for me. conversion in client side or server side i am not concerned with that right now. – user3318209 Apr 08 '15 at 11:32

1 Answers1

0

Try to not use JSON.stringify(tree); this escapes the string.

Set var xmlAsStr = x2js.json2xml_str(tree);