Skip to content

Instantly share code, notes, and snippets.

@ssullivan
Created April 16, 2020 01:22
Show Gist options
  • Select an option

  • Save ssullivan/e8cf422e500e76714c42d41738010a44 to your computer and use it in GitHub Desktop.

Select an option

Save ssullivan/e8cf422e500e76714c42d41738010a44 to your computer and use it in GitHub Desktop.
Daffodil Parse
public static ProcessorFactory compileSchema(final String schema)
throws URISyntaxException, IOException {
Compiler compiler = Daffodil.compiler();
ProcessorFactory factory = compiler.compileSource(Resources.getResource(schema).toURI());
if (factory.isError()) {
factory.getDiagnostics()
.forEach(diagnostic -> {
LOGGER.error(diagnostic.getMessage(), diagnostic.getSomeCause());
});
throw new RuntimeException("Failed to compile schema");
}
return factory;
}
Compiler compiler = Daffodil.compiler();
ProcessorFactory factory = compileSchema(schema);
try (ByteArrayOutputStream buffer = new ByteArrayOutputStream()) {
InputSourceDataInputStream source = new InputSourceDataInputStream(Resources.getResource(
file).openStream());
XMLTextInfosetOutputter outputter = new XMLTextInfosetOutputter(buffer, true);
DataProcessor dataProcessor = factory.onPath("/");
dataProcessor.setDebugging(true);
dataProcessor.setDebugger(new TraceDebuggerRunner());
ParseResult parseResult = dataProcessor.parse(source, outputter);
MatcherAssert.assertThat("No processing errors", parseResult.isProcessingError(),
CoreMatchers.equalTo(false));
MatcherAssert.assertThat("No validation errors", parseResult.isValidationError(),
CoreMatchers.equalTo(false));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment