从SOAP api调用中检索并解析XMLresponse

时间:2017-01-20 11:38:23

标签: json node.js xml soap

我使用此代码来检索JSON响应。



var loopback = require('loopback');
var ds = loopback.createDataSource('soap', {
  connector: require('loopback-connector-soap'),
  wsdl: 'http://www.webservicex.net/stockquote.asmx?WSDL', // The url to WSDL
  url: 'http://www.webservicex.net/stockquote.asmx', // The service endpoint

  // Map SOAP service/port/operation to Node.js methods
  operations: {
    // The key is the method name
    stockQuote: {
      service: 'StockQuote', // The WSDL service name
      port: 'StockQuoteSoap', // The WSDL port name
      operation: 'GetQuote' // The WSDL operation name
    },
    // The key is the method name
    stockQuote12: {
      service: 'StockQuote', // The WSDL service name
      port: 'StockQuoteSoap12', // The WSDL port name
      operation: 'GetQuote' // The WSDL operation name
    }
  }

});

//  wait for the methods to be injected
ds.once('connected', function() {
  // Create the model
  var StockQuote = ds.createModel('StockQuote', {});

  StockQuote.stockQuote({
    symbol: 'IBM'
  }, function(err, response) {
    console.log('Response: ', response);
  });

  StockQuote.stockQuote12({
    symbol: 'FB'
  }, function(err, response) {
    console.log('Response: ', response);
  });


});




我得到了以下回应。屏幕截图如下所示。 enter image description here 现在我如何访问响应的每个元素? 我尝试用this方式做,

var testout= response["Stock"].Symbol;
console.log(testout);

但我刚收到错误。

如何访问响应的每个XML字段?

here FYI获得了初始源代码。 任何帮助将不胜感激。

0 个答案:

没有答案