I found this nice simple jquery plugin that helps convert xml string into JSON object directly converts xml string into json object in javascript. Following is a simple html file that I used to test my way through with this plugin. So my motive is to get a message box in the browser saying “Hello World” through the following file. Hope I don’t have to speak much about this file as its very plain and simple
----------------------------------------------------------------------------------------------------------------------------
<html>
<head>
<script type='text/javascript' src='jquery.js'></script>
<script type='text/javascript' src='jquery.xml2json.js'></script>
<script type='text/javascript'>
function xmlToJsonTest() {
var xml = '<xml><message>Hello world</message></xml>';
var json = $.xml2json(xml);
alert(json.message);
}
</script>
</head>
<body onload='xmlToJsonTest()'>XML To JSON Test</body>
</html>
----------------------------------------------------------------------------------------------------------------------------
You can find this xml to json convertor jquery plugin in http://www.fyneworks.com/jquery/xml-to-json/ .
You can go through the site for examples and if you would like to skip the hard part here is the direct download link for the same site for the plugin http://jquery-xml2json-plugin.googlecode.com/svn/trunk/jquery.xml2json.js
Hope this helps
No comments:
Post a Comment