Reputation: 65
I try retrieving data from an api which is in xml format. I've source for few examples calling json file but couldn't get it done calling an api.
Here is my code. it shows nothing on the browser and It does not show any error in the console log
angular.module('myApp', [])
.controller('foodListController', function($scope, $http) {
$http.get('mydomain.com/api/FoodList/GetAllList').then(function (response) {
$scope.myData = response.data.dtoFood;
});
});
<ul>
<li ng-repeat="x in myData">
{{ x.FoodName + ', ' + x.IsActive }}
</li>
</ul>
<ArrayOfdtoFood>
<dtoFood>
<CreatedBy i:type="d3p1:string">1</CreatedBy>
<CreatedOn>2016-02-01T17:22:31.645Z</CreatedOn>
<IsActive>true</IsActive>
<IsChecked i:nil="true"/>
<IsDelete i:nil="true"/>
<ModifiedOn>2016-02-20T08:06:31.905Z</ModifiedOn>
<Modifiedby i:type="d3p1:string">1</Modifiedby>
<FoodName>Example1</FoodName>
</dtoFood>
<dtoFood>
<CreatedBy i:type="d3p1:string">1</CreatedBy> <CreatedOn>2016-02-01T17:22:31.645Z</CreatedOn>
<IsActive>true</IsActive>
<IsChecked i:nil="true"/>
<IsDelete i:nil="true"/>
<ModifiedOn>2016-02-20T08:06:31.905Z</ModifiedOn>
<Modifiedby i:type="d3p1:string">1</Modifiedby>
<FoodName>Example Food 2</FoodName>
</dtoFood>
</ArrayOfdtoFood>
Upvotes: 0
Views: 1680
Reputation: 1162
You could do that this way using x2js:
var x2js = new X2JS();
$scope.list = x2js.xml_str2json("<data><obj><item>1</item></obj><obj><item>2</item></obj></data>");
console.log($scope.list);
see the fiddle.
This will work, of course if the service is giving a response and is valid XML.
Are you loading data from an absolute url...?
Upvotes: 1