this is my first SwitchScript with Node.js envolved.
I want to use a third party package from npm that can validate XML against a XSD.
I picked this one https://www.npmjs.com/package/libxmljs2-xsd.
My code:
Code: Select all
const xsd = require('libxmljs2-xsd');
const fs = require('fs');
async function jobArrived(s, flowElement, job) {
let xsdPath = await flowElement.getPropertyStringValue("xsdPath");
await job.log(LogLevel.Info,'%1',[xsdPath]);
//const jobName = await getName();
const jobTempPath = await job.get(AccessLevel.Read);
const schema = await xsd.parseFile(xsdPath);
let documentString = await fs.readdirSync(jobTempPath)
let validationErrors = await schema.validate(documentString);
if (validationErrors === null){
job.sendToData(Connection.Level.Success);
} else{
job.log(LogLevel.Info,'%1',[validationErrors]);
job.sendToData(Connection.Level.Warning);
}
}
I have a Package.json:
I did "npm install libxmljs2-xsd" as documented.....
"dependencies": {
"libxmljs2-xsd": "^0.28.0"
}
}
And also my propertie xsdPath is setup: The errormessage says:
So what am I missing here? Is the module not supported? How can I know?Cannot find module 'C:\Users\myservername\AppData\Roaming\Enfocus\SwitchProcessorService\cache\031f213823b89b1725061c482e50b2e67622a913232442f6e415d8f18ec5c267\1638795351\node_modules\libxmljs2-xsd' Require stack: - C:\Program Files\Enfocus\Enfocus Switch\ScriptExecutor\NodeScriptExecutor.js