将javascript变量传递给XML body node.js
我希望将post请求中得到的变量传递到xml正文中,以调用Web服务。如何将javascript变量传递到xml将javascript变量传递给XML body node.js,javascript,node.js,xml,Javascript,Node.js,Xml,我希望将post请求中得到的变量传递到xml正文中,以调用Web服务。如何将javascript变量传递到xml router.post('/', async (req, res) => { const sorguNo= req.body.sorguNo; 我从post请求中获取的变量 在这里,我想使用sonucNo字段中的变量 这可以通过以下方式实现: const sonucNo=你好; 常量xml=` ${sonucNo} `; console.logxml;您的xlm只是一个字
router.post('/', async (req, res) => {
const sorguNo= req.body.sorguNo;
我从post请求中获取的变量
在这里,我想使用sonucNo字段中的变量
这可以通过以下方式实现:
const sonucNo=你好;
常量xml=`
${sonucNo}
`;
console.logxml;您的xlm只是一个字符串。您可以使用模板字符串创建多行字符串,在其中可以插入变量。正如您所说,使用反勾号解决了问题。谢谢
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="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
'<soap:Header>' +
'<AuthHeader xmlns="http:">' +
'<userName>username</userName>' +
'<password>password</password>' +
'</AuthHeader>' +
'</soap:Header>' +
'<soap:Body>' +
'<xmlns="http:..">' +
'<sonucNo></sonucNo>' +
'</>' +
'</soap:Body>' +
'</soap:Envelope>';