How to handle XML services in AngularJS?

后端 未结 5 1183
误落风尘
误落风尘 2020-11-27 04:37

My company has thousands of existing xml web services and is starting to adopt AngularJs for new projects.

The tutorial over at http://angularjs.org/ uses json servi

5条回答
  •  南方客
    南方客 (楼主)
    2020-11-27 04:46

    I created a service named HttpService having a function called getRequestedContent in which I am using angular http call to my service "http://localhost:8080/showserverstartupinfo" which returns a xml as follows:

    
    ########
    ##########
    
    

    ...and I parse the above xml and populate my div with content of xml element.

    HttpService.getRequestedContent('/showserverstartupinfo').then(
      function(content) {
        //successCallback
        var xml = content.data;
        document.getElementById('serverName').innerHTML = 
              xml.getElementsByTagName("SERVERNAME")[0].childNodes[0].nodeValue;
      }, function(data) {
        //errorCallback
    });
    

    getRequestedContent function in HttpService(Angularjs) as follows:

    getRequestedContent : function(request) {
      var url = this.getRootContextPath() + request;
      return $http({
        method : 'GET',
        url : url,
        transformResponse : function(data) {
          return $.parseXML(data);
        }
      });
    }
    

提交回复
热议问题