Parsing edi file with interchange & transaction message => jaxb #249
-
Hi ... first of all thanks for this powerful tool <3 I am currently trying to import an edi file (AO06Q122.zip) with the following structure:
So in my case it seems like i need the interchange schema + a separate transaction schema. My goal is to import this as a pojo with jaxb. Here is a code snippet:
My Problem is now that i dont know how to pass the transaction schema to the XMLStreamReader. Here is a my code snippet with a combination of edi and xml reader:
Edit: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@vadim-trotno You can accomplish this using an EDIStreamReader reader = factory.createEDIStreamReader(stream);
EDIStreamFilter filter = new MyCustomFilter();
EDIStreamReader filteredReader = factory.createFilteredReader(reader, filter); class MyCustomFilter implements EDIStreamFilter {
public boolean accept(EDIStreamReader reader) {
if (reader.getEventType() == EDIStreamEvent.START_TRANSACTION) {
SchemaFactory schemaFactory = SchemaFactory.newFactory();
Schema txSchema = schemaFactory.createSchema(new FileInputStream("./payer_transaction_schema.xml"));
reader.setTransactionSchema(txSchema);
}
return true; // allowing all events through filter
}
} |
Beta Was this translation helpful? Give feedback.
@vadim-trotno You can accomplish this using an
EDIStreamFilter
. After you build theEDIStreamReader
, you can wrap it with a filter that will set the schema at the relevant event. This will intercept the reader as it feeds EDI data into the XML reader that was also created from the factory.