最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

将javascript变量传递给XML body node.js

运维笔记admin10浏览0评论

将javascript变量传递给XML body node.js

将javascript变量传递给XML body node.js

我想将从post请求获得的变量传递给xml正文以调用webservice。如何将javascript变量传递给xml?

router.post('/', async (req, res) => {
const sorguNo= req.body.sorguNo; 

我从post请求获得的变量

      const url = 'Url';
       const headers = {
      'Content-Type': 'text/xml; charset=utf-8',
      'soapAction': 'Soap Action'
         };
    const xml = '<?xml version="1.0" encoding="utf-8"?>'+
    '<soap:Envelope xmlns:xsi="" 
    xmlns:xsd="" 
    xmlns:soap="/">' +
      '<soap:Header>' +
        '<AuthHeader xmlns="http:">' +
          '<userName>username</userName>' +
           '<password>password</password>' +
        '</AuthHeader>' +
      '</soap:Header>' +
    '<soap:Body>' +
        '<xmlns="http:..">' +
          '<sonucNo></sonucNo>' + 

在这里我想在sonucNo字段中使用变量

        '</>' +
      '</soap:Body>' +
    '</soap:Envelope>';
回答如下:

这可以使用template literals完成:

const sonucNo = "hello";
const xml = `<?xml version="1.0" encoding="utf-8"?>
  <soap:Envelope>
    <sonucNo>${sonucNo}</sonucNo>
  </soap:Envelope>`;

console.log(xml);
发布评论

评论列表(0)

  1. 暂无评论