How to parse garbled xml (ofx) usingx4j?

I am desperately trying to use the following library: ofx4j . But the documentation regarding parsing the inx file is a bit easier. It says: if you have a file or other stream resource, you can read it using an instance of net.sf.ofx4j.io.OFXReader

OK, but how to do it?

It also states the following: if you want to decouple OFX directly with a Java object, use net.sf.ofx4j.io.AggregateUnmarshaller.

Good, but it's a little complicated for me. Is there something obvious that I missed? When I try to use unmarshaller, it asks me to implement an interface.

Can someone point me to an online resource explaining the bits that I am missing? Or is it better that you understand from the previous statements regarding xreader and unmarshaller?

Please do not bash me, I am learning java with playframework and I would really appreciate the opportunity to parse these .x / files

early.

+2
java xml ofx
source share
2 answers

I don't see a simple old tutorial, but there is sample code in the test directory that illustrates OFXReader and AggregateUnmarshaller .

The phrase "instance of net.sf.ofx4j.io.OFXReader " means one of the well-known implementation classes ", for example NanoXMLOFXReader , which is tested here . The test for AggregateUnmarshaller here .

APIs and mail archives are also good resources. Many institutions seem to be participating.

+5
source share

For those who stumble upon this, as I did when I couldn’t get the expected results from AggregateUnmarshaller ... Here is an example.

 //Using a multipart file, but using a regular file is similar. public void parse(MultipartFile file) throws IOException { //Use ResponseEnvelope to start. AggregateUnmarshaller<ResponseEnvelope> unmarshaller = new AggregateUnmarshaller<ResponseEnvelope>( ResponseEnvelope.class); try { ResponseEnvelope envelope = unmarshaller.unmarshal(file.getInputStream()); //Assume we are just interested in the credit card info. Make sure to cast. CreditCardResponseMessageSet messageSet = (CreditCardResponseMessageSet) envelope .getMessageSet(MessageSetType.creditcard); List<CreditCardStatementResponseTransaction> responses = messageSet.getStatementResponses(); for (CreditCardStatementResponseTransaction response : responses) { CreditCardStatementResponse message = response.getMessage(); String currencyCode = message.getCurrencyCode(); List<Transaction> transactions = message.getTransactionList().getTransactions(); for (Transaction transaction : transactions) { System.out.println(transaction.getName() + " " + transaction.getAmount() + " " + currencyCode); } } } catch (OFXParseException e) { e.printStackTrace(); } } 
+2
source share

All Articles