Here you go...
Your 5000 line hard coded function becomes 100% dynamic (1 row or 10000 rows - its the same)...
//make the base JS object
var dataStructure ={
"LPListAuditSearchResult":{
"$": {
"xmlns":"http://www.std-cgi.org/ver20/XMLSchema","version":"2.0"
},
"LicensePlateInfoList": [
{
"LicensePlateInfo":[ ]
}
]
}
}
//make a data item from a DB row
function makeDataRow(row) {
return {
"id":[row.id],
"LicensePlate":[row.Kenteken],
"type":[row.Type],
"effectiveTime":[row.Geldig]
}
}
for (let i = 0; i < msg.payload.length; i++) {
const row = msg.payload[i];
//add the converted DB row to the JS dataStructure object
dataStructure.LPListAuditSearchResult.LicensePlateInfoList[0].LicensePlateInfo.push(makeDataRow(row));
}
msg.payload = dataStructure
return msg;
Demo flow...
[{"id":"2ebcaf60.912b7","type":"inject","z":"4656711a.6b16a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":330,"y":280,"wires":[["d818ecec.c4de"]]},{"id":"d818ecec.c4de","type":"function","z":"4656711a.6b16a","name":"Database data (fake query result)","func":"msg.payload = [{\"id\":1,\"Kenteken\":\"34jlrd\",\"Type\":\"blackList\",\"Geldig\":\"2020-12-12\",\"AantalKeren\":\"44\"},{\"id\":2,\"Kenteken\":\"68-bg-po\",\"Type\":\"whiteList\",\"Geldig\":\"2020-12-12\",\"AantalKeren\":\"48\"},{\"id\":3,\"Kenteken\":\"01aa01\",\"Type\":\"blackList\",\"Geldig\":\"2020-12-12\",\"AantalKeren\":\"48\"},{\"id\":4,\"Kenteken\":\"02aa01\",\"Type\":\"whiteList\",\"Geldig\":\"2020-12-12\",\"AantalKeren\":\"48\"},{\"id\":6,\"Kenteken\":\"04aa01\",\"Type\":\"whiteList\",\"Geldig\":\"2020-12-12\",\"AantalKeren\":\"48\"}]\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":580,"y":280,"wires":[["5f772990.9cb2b8","b2fc9b8f.7fef28"]]},{"id":"5f772990.9cb2b8","type":"debug","z":"4656711a.6b16a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":930,"y":280,"wires":[]},{"id":"b2fc9b8f.7fef28","type":"function","z":"4656711a.6b16a","name":"transform to nice JS object","func":"//make the base JS object\nvar dataStructure ={\n \"LPListAuditSearchResult\":{\n \"$\": {\n \"xmlns\":\"http://www.std-cgi.org/ver20/XMLSchema\",\"version\":\"2.0\"\n },\n \"LicensePlateInfoList\": [\n {\n \"LicensePlateInfo\":[ ]\n }\n ]\n }\n}\n\n//make a data item from a DB row\nfunction makeDataRow(row) {\n return {\n \"id\":[row.id],\n \"LicensePlate\":[row.Kenteken],\n \"type\":[row.Type],\n \"effectiveTime\":[row.Geldig]\n }\n}\n\nfor (let i = 0; i < msg.payload.length; i++) {\n const row = msg.payload[i];\n //add the converted DB row to the JS dataStructure object\n dataStructure.LPListAuditSearchResult.LicensePlateInfoList[0].LicensePlateInfo.push(makeDataRow(row));\n}\nmsg.payload = dataStructure\nreturn msg;\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":560,"y":340,"wires":[["ecb6b334.0d41","61af7ae1.0ee784"]]},{"id":"ecb6b334.0d41","type":"xml","z":"4656711a.6b16a","name":"","property":"payload","attr":"","chr":"","x":770,"y":340,"wires":[["497a134c.f828fc"]]},{"id":"497a134c.f828fc","type":"debug","z":"4656711a.6b16a","name":"Finished XML","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":940,"y":340,"wires":[]},{"id":"61af7ae1.0ee784","type":"debug","z":"4656711a.6b16a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":790,"y":400,"wires":[]}]
PS - your original XML is still invalid (and the exact reason I said you should work with Js objects instead of a hand coded string concatenation)