As you all know Angular JS is a JavaScript framework for developing applications. So basically Angular JS expects the response in the form of JSON. Hence it is recommended to return the data in JSON format before you start to work on the data. Here in this post, we will load a local XML file using Angular JS $http service, and we will convert the same XML file to JSON. Once it is converted, we will loop through the JSON and show it as li using ng-repeat. If you are new to Angular JS, please read here.
Background
To convert your XML file to JSON, I recommend you to read here.
Using the code
Create an HTML page first.
<!DOCTYPE html>
<html>
<head>
<title>Load XML And Show As li In Angular JS - SibeeshPassion </title>
</head>
<body>
</body>
</html>
Now add the needed reference as follows.
<script src="jquery-2.1.3.min.js"></script>
<script src="angular.min.js"></script>
<script src="xml2json.js"></script>
Have you noticed that I have added the xml2json.js file? This is the file that is doing the conversion part. You can always download the file from https://code.google.com/p/x2js/.
So if you read and implement as explained in my article on converting XML files to JSON in Angular JS, Your page will look as follows.
<!DOCTYPE html>
<html>
<head>
<title>Convert XML to JSON In Angular JS - SibeeshPassion</title>
<script src="jquery-2.1.3.min.js"></script>
<script src="angular.min.js"></script>
<script src="xml2json.js"></script>
</head>
<body>
<div ng-app="httpApp" ng-controller="httpController"></div>
<script>
var app = angular.module('httpApp', []);
app.controller('httpController', function ($scope, $http) {
$http.get("Sitemap.xml", {
transformResponse: function (cnv) {
var x2js = new X2JS();
var aftCnv = x2js.xml_str2json(cnv);
return aftCnv;
}
}).success(function (response) {
console.log(response);
});
});
</script>
</body>
</html>
So we have loaded our XML and converted it to the JSON. Now we need to show this JSON response as li using ng-repeat in Angular JS. Are you ready?
For that please change your ng-app directive as follows.


Sibeesh VenuPosted Mar 30, 2016, 5:11 AM
Rajeev Punhani Thanks
Rajeev PunhaniPosted Mar 30, 2016, 4:50 AM
Nice article.
Sibeesh VenuPosted Jan 17, 2016, 11:58 PM
Arul R Thanks a lot
Arul RPosted Jan 17, 2016, 11:05 AM
Thanks for nice article
Sibeesh VenuPosted Nov 11, 2015, 8:08 AM
Santhakumar Munuswamy Thanks a lot
Santhakumar MunuswamyPosted Nov 11, 2015, 8:04 AM
Good one
Sibeesh VenuPosted Nov 8, 2015, 11:18 PM
Harshad Pansuriya Thank you
Sibeesh VenuPosted Nov 8, 2015, 11:18 PM
Mukesh Kumar Thanks buddy
Harshad PansuriyaPosted Nov 8, 2015, 11:07 PM
Nice one
Mukesh KumarPosted Nov 8, 2015, 12:33 PM
Good Job Sibeesh Sir
Sibeesh VenuPosted Nov 7, 2015, 11:14 PM
Gowtham K Thank you
Sibeesh VenuPosted Nov 7, 2015, 11:14 PM
Gul Md Ershad Thank you
Gowtham KPosted Nov 7, 2015, 10:07 AM
Good One
Former memberPosted Nov 7, 2015, 9:36 AM
Nice one
Sibeesh VenuPosted Nov 7, 2015, 9:09 AM
Manoj Kulkarni Thank you so much
Manoj KulkarniPosted Nov 7, 2015, 7:37 AM
Nice article. Thank you for sharing