Guest User

EdiToXmlChange

a guest
Mar 24th, 2025
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. protected static String runSmooksTransform() throws IOException, SAXException, SmooksException {
  2. // Configure Smooks using a Smooks config...
  3. Smooks smooks = new Smooks(new DefaultApplicationContextBuilder().withClassLoader(Main.class.getClassLoader()).build());
  4. // smooks.addResourceConfigs("smooks-config.xml");
  5.  
  6. smooks.setReaderConfig(new EdifactReaderConfigurator("/d03b/EDIFACT-Messages.dfdl.xsd"));
  7. ResourceConfig edifactParser = new DefaultResourceConfig("*", new Properties());
  8. edifactParser.setParameter("cacheOnDisk", "true");
  9. smooks.addResourceConfig(edifactParser);
  10. // Or, configure Smooks programmatically...
  11. // final Smooks smooks = new Smooks();
  12. // smooks.setReaderConfig(new EdifactReaderConfigurator("/d03b/EDIFACT-Messages.dfdl.xsd").setMessageTypes(Arrays.asList("PAXLST")));
  13.  
  14. try {
  15. final StringWriter writer = new StringWriter();
  16. smooks.filterSource(new StreamSource<>(Main.class.getResourceAsStream("/PAXLST.edi")), new WriterSink<>(writer));
  17.  
  18. return writer.toString();
  19. } finally {
  20. smooks.close();
  21. }
  22. }
  23.  
Advertisement
Add Comment
Please, Sign In to add comment