Created
April 16, 2020 01:22
-
-
Save ssullivan/e8cf422e500e76714c42d41738010a44 to your computer and use it in GitHub Desktop.
Daffodil Parse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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