Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
"i have made a json jn javascript and now 'i want to code the same but in XML. How will I get a desired result with it..

[^]

What I have tried:

This is JSON and its XML is :
XML
<?xml version="1.0" encoding="UTF-8" ?>
<cars>
  <Honda>
    <model>Figo</model>
  </Honda>
  <Honda>
    <model>City</model>
  </Honda>
  <Audi>
    <model>A6</model>
  </Audi>
  <Audi>
    <model>A8</model>
  </Audi>
</cars>
Posted
Updated 20-Apr-16 23:42pm
Comments
Karthik_Mahalingam 21-Apr-16 5:10am    
could you post your json data

use xml2json.js

var x2js = new X2JS();

function convertXml2JSon() {
$("#jsonArea").val(JSON.stringify(x2js.xml_str2json($("#xmlArea").val())));
}

function convertJSon2XML() {
$("#xmlArea").val(x2js.json2xml_str($.parseJSON($("#jsonArea").val())));
}

$("#xmlArea").val("<root><child><textnode>First & Child<child><textnode>Second Child<testattrs attr1="attr1Value">");

convertXml2JSon();
 
Share this answer
 
The problem with xml parsing is that there are few standard ways that work on all browsers, they didn't really get their stuff together with xml the way they have json. Google "parse xml with javascript" for examples, but to make it as easy as possible you're better using a plugin or framework where someone has worked all the cross-browser issues out for you.

jQuery.parseXML() | jQuery API Documentation[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900