将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);
将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);