JSFiddle - React, Tailwind, and code Playground
by Kiwoong Jang
HTML
<script src="https://x2js.googlecode.com/hg/xml2json.js"></script>
<div ng-app="xmlparseApp">
<div ng-controller="xmlParseController">
</div>
</div>
JavaScript
angular.module("xmlparseApp", []).
factory("DataSource", [ "$http", function($http) {
return {
get: function(url, callback, transform) {
$http.get(url, { transformResponse: transform }).
success(function(data, status) {
console.log(status);
callback(data);
}).
error(function(data, status) {
console.log(status);
});
}
};
}]);
var xmlParseController = function($scope, DataSource) {
xmlTransform = function(data) {
var x2js = new X2JS(),
json = x2js.xml_str2json(data);
return json;
};
setData = function(data) {
$scope.dataSet = data;
};
DataSource.get("http://www.maniadb.com/api/search/%EC%84%9C%ED%83%9C%EC%A7%80/?sr=artist&display=10&key=example&v=0.5", setData, xmlTransform);
};