[英]Send message to the new destination in Mirth
我在 Mirth 频道上工作,我正在尝试使用 XSD 文件验证 XML。 为了实现这一点,我编写了下面的 JavaScript 来满足我的目的。 我正在使用 JAXP API 库来执行此操作。
我的下一步是:任何验证错误都应路由到目标 1。而有效消息应路由到目标 2。
如果有人可以指导我如何调整此 Javascript 或编写过滤器逻辑来执行此操作,我将不胜感激。
提前致谢!!!
var schemaFile = new Packages.java.io.File("C:\\hl7v3\\Test.xsd");
var schemaFactory = Packages.javax.xml.validation.SchemaFactory.newIns tance("http://www.w3.org/2001/XMLSchema");
var schema = schemaFactory.newSchema(schemaFile);
var reader = new Packages.java.io.StringReader(connectorMessage.get RawData());
var xmlFile = new Packages.javax.xml.transform.stream.StreamSource(r eader);
var validator = schema.newValidator();
try {
// validates the message
validator.validate(xmlFile);
// valid message
logger.info('valid');
} catch (err) {
// invalid message
logger.error('An Error Occurred:'+err.toString());
return false;
}
对于上面的验证示例,我们可以使用 Mirth destinationSet 过滤功能,如下所示,
我们应该有两个目标连接器,一个用于有效消息传输,另一个用于错误消息
try {
// validates the message
validator.validate(xmlFile);
// valid message
logger.info('valid');
destinationSet.removeAllExcept(<sucess-destination-id>);
} catch (err) {
// invalid message
logger.error('An Error Occurred:'+err.toString());
destinationSet.removeAllExcept(<error-destination-id>);
return false;
}
//Replace destination ID based on your destination IDs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.