I have this code to make a validation of a XML file with a XSD. And this code works!
var schemaFile = new Packages.java.io.File("C:\\schema.xsd");
var url = new Packages.java.net.URL("file:C:\\input.xml");
var xmlFile = new Packages.javax.xml.transform.stream.StreamSource(url);
var schemaFactory = Packages.javax.xml.validation.SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
var schema = schemaFactory.newSchema(schemaFile);
var validator = schema.newValidator();
try {
validator.validate(xmlFile);
logger.info('valid');
} catch (err) {
logger.error(err.toString());
}
But now, instead of using a XML file as input in here
var xmlFile = new Packages.javax.xml.transform.stream.StreamSource(url);
I want to use a variable, passed before, that has a XML in it. If I write the variable there
var xmlFile = new Packages.javax.xml.transform.stream.StreamSource(msg);
I get an error protocol
JavaException: java.net.MalformedURLException: no protocol:
This is because StreamSource needs a specified protocol, for a File it was easy (file:path). How can I put there a variable instead of a file?