2

I am trying to fetch an XML feed from the same domain but the obj is returning null. Below is my code.

Service

angular.module('ngAuidApp')
  .service('profileInfoService', function($http){
    return $http.get('scripts/user-feed.xml');
  });

Controller

angular.module('ngAuidApp')
  .controller('ProfileCtrl', ['$scope', 'x2js', 'profileInfoService', function ($scope, x2js, profileInfoService) {

    var xmlObj = '<feed><title type="text">User Ashish Panchal - Stack Overflow</title><link rel="self" href="http://stackoverflow.com/feeds/user/3635285" type="application/atom+xml" /><link rel="alternate" href="http://stackoverflow.com/users/3635285" type="text/html" /></feed>';

    var jsonOb = x2js.xml_str2json(xmlObj);

    // Prints title from above xml string
    console.log(jsonOb.feed.title);

    // Trying to fetch from external file
    profileInfoService.success(function(data){
      // Print outs xml feed
      console.log(data);

      var jsonObj = x2js.xml_str2json(data);

      // Prints null
      console.log(jsonObj);

    });
  }]);

When I am trying to fetch feed from external file it gives null. Can someone please let me know what is missing?

1 Answer 1

2

error in your xml file not in code. Please remove this ":" from you xml attribute Example change

<re:rank> to <rerank>
Sign up to request clarification or add additional context in comments.

1 Comment

You're right, my script was correct. There was problem with my xml feed, I took new feed and it worked.... btw I don't need to rename the <re:rank>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.