Loading data from xml

4,186 views
Skip to first unread message

Bhushan N.N

unread,
Feb 20, 2013, 12:17:36 PM2/20/13
to ang...@googlegroups.com
Hi All,

I have tried loading data from a JSON file and it worked like a charm. I am trying the same for an xml file but doesn't seem to work. How or what would be the approach to load data from an xml file?

JSON - Worked
$scope.seats = [];
$http.get('seats/seats.json').success(function(data) {
$scope.seats = data;
});

XML - Not working
$scope.data = [];
$http.get('data/test.xml').success(function(data) {
$scope.data = data;
});

Thank you
Bhushan

Peter Bacon Darwin

unread,
Feb 20, 2013, 1:52:37 PM2/20/13
to ang...@googlegroups.com
What do you get in data? A string?


Bhushan

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Bhushan N.N

unread,
Feb 20, 2013, 8:19:12 PM2/20/13
to ang...@googlegroups.com
Yes I am getting a String value in data.

Chris Huston

unread,
Feb 20, 2013, 9:32:24 PM2/20/13
to ang...@googlegroups.com
You will probably need to parse the xml into a JSON object. There are a number of converters out there that get the job done, but may require a bit of customization depending on the structure of your xml. Here are two:


Chris

Bhushan N.N

unread,
Feb 21, 2013, 12:14:07 PM2/21/13
to ang...@googlegroups.com
Thanks Chris,


        $scope.data = [];
$http.get('data/test.xml').success(function(data) {
$scope.data=$.xml2json( data, true) ;
});

Rohit Salviya

unread,
Mar 17, 2015, 9:08:44 AM3/17/15
to ang...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages