I'm trying to make a soap request using the method as described here: https://www.npmjs.com/package/soap#example-with-xml-string-for-the-args.
I want to input a xml string instead of a JSON object since i can't achieve the required syntax in JSON.
const url = 'https://www.cashweb.nl/?api/3.0/wsdl';
const xmlStr = "<test></test>"
soap.createClient(url, function (err, client) {
if (err) {
response.status(500)
response.send("error creating client")
}
client.Import({ _xml: xmlStr }, function (err, result, rawResponse, soapHeader, rawRequest) {
// result is a javascript object
// rawResponse is the raw xml response string
// soapHeader is the response soap header as a javascript object
// rawRequest is the raw xml request string
if (err) {
response.status(500)
response.send(err + " " + rawRequest)
}
response.status(200)
response.send(rawRequest + " " + rawResponse)
})
});
Though this gives me the unwanted output:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="https://www.cashweb.nl/?api/3.0" xmlns:ns="https://www.cashweb.nl/?api/3.0">
<soap:Body>
<tns:Import>
<_xml>
<test/>
</_xml>
</tns:Import>
</soap:Body>
</soap:Envelope>
How do I get rid of the <_xml> and tags. Am I using the funcion incorrectly?
Example found in node-soap tests https://github.com/vpulim/node-soap/blob/70c4f34b6370ffc59e7d4fe88d18d6312ff0bedc/test/client-test.js:
it('should allow passing in XML strings', function (done) {
soap.createClientAsync(__dirname + '/wsdl/default_namespace.wsdl', _.assign({envelopeKey: 'soapenv'}, meta.options))
.then(function (client) {
assert.ok(client);
var xmlStr = '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n\t<head>\n\t\t<title>404 - Not Found</title>\n\t</head>\n\t<body>\n\t\t<h1>404 - Not Found</h1>\n\t\t<script type="text/javascript" src="http://gp1.wpc.edgecastcdn.net/00222B/beluga/pilot_rtm/beluga_beacon.js"></script>\n\t</body>\n</html>';
return client.MyOperationAsync({_xml: xmlStr});
})
.spread(function (result, raw, soapHeader) {})
.catch(function (err) {
done();
});
});
I'm trying to accomplish this because my Soap Api requires a CDATA tag in the following manner:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:api="https://www.cashweb.nl/?api">
<soapenv:Header/>
<soapenv:Body>
<api:Import>
<relatie>202943</relatie>
<email>helpdesk@cash.nl</email>
<pass>*********</pass>
<importData>
<![CDATA[<?xml version="1.0">
<CASH>
<R0301>
<F201>4360</F201>
<F302>161201</F302>
<F306>kantoorbenodigdheden</F306>
<F307>10000</F307>
<F901>KAS</F901>
</R0301>
</CASH>]]>
</importData>
<administration>
<api:admCode>demo</api:admCode>
<api:admMap/>
</administration>
<formaat>0</formaat>
</api:Import>
</soapenv:Body>
</soapenv:Envelope>