Skip to content

Instantly share code, notes, and snippets.

@z3bbster
Last active December 17, 2015 12:39
Show Gist options
  • Save z3bbster/5611424 to your computer and use it in GitHub Desktop.
Save z3bbster/5611424 to your computer and use it in GitHub Desktop.
//how to convert xml to json using jquery
// http://www.fyneworks.com/jquery/xml-to-json/#tab-Usage
/*
XML File:
<gesmes:Envelope xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01" xmlns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref">
<gesmes:subject>Reference rates</gesmes:subject>
<gesmes:Sender>
<gesmes:name>European Central Bank</gesmes:name>
</gesmes:Sender>
<Cube>
<Cube time="2013-05-17">
<Cube currency="USD" rate="1.2869"/>
<Cube currency="JPY" rate="131.87"/>
<Cube currency="BGN" rate="1.9558"/>
...
</Cube>
</Cube>
</gesmes:Envelope>
*/
$.get('data/eurofxref-daily.xml', function(xml) {
var jsonObj = $.xml2json(xml);
alert(jsonObj.Cube.Cube.Cube[0]["rate"]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment