[英]Passing a javascript variable to XML body node.js
我想将我从发布请求中获得的变量传递给xml主体,以调用Web服务。 如何将JavaScript变量传递给xml?
router.post('/', async (req, res) => {
const sorguNo= req.body.sorguNo;
我从发布请求中获取的变量
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>' +
在这里我想在sonucNo字段中使用变量
'</>' +
'</soap:Body>' +
'</soap:Envelope>';
这可以使用模板文字来完成:
const sonucNo = "hello"; const xml = `<?xml version="1.0" encoding="utf-8"?> <soap:Envelope> <sonucNo>${sonucNo}</sonucNo> </soap:Envelope>`; console.log(xml);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.