ofx4j で不正な XML (ofx) を解析するにはどうすればよいですか?

StackOverflow https://stackoverflow.com/questions/2221608

  •  19-09-2019
  •  | 
  •  

質問

私は必死に次のライブラリを使用しようとしています: ofx4j. 。ただし、ofx ファイルの解析に関するドキュメントは少し内容が薄いです。それはこう言います:ファイルまたはその他のストリーム リソースがある場合は、net.sf.ofx4j.io.OFXReader のインスタンスを使用してそれを読み取ることができます。

わかりましたが、どうすればいいですか?

また、次のようにも述べられています。OFX を Java オブジェクトに直接アンマーシャリングする場合は、net.sf.ofx4j.io.AggregateUnmarshaller を使用します。

わかりましたが、私にとっては少し複雑です。明らかに見逃しているものはありますか?アンマーシャラーを使用しようとすると、インターフェイスを実装するように求められます。

誰かが私に足りない部分を説明しているオンラインリソースを教えてくれませんか?あるいは、ofxreader と unmarshaller に関する前のステートメントから何を理解できますか?

私を叩かないでください。私は Playframework で Java を学んでいるので、これらの ofx ファイルを解析できることを本当に感謝しています。

前もって感謝します。

役に立ちましたか?

解決

単純な古いチュートリアルはありませんが、サンプルコードはあります テスト を説明するディレクトリ OFXReader そして AggregateUnmarshaller.

「の例」というフレーズ net.sf.ofx4j.io.OFXReader「既知の実装クラスの 1 つを意味します」など NanoXMLOFXReader, 、つまり ここでテストされました. 。のためのテスト AggregateUnmarshallerここ.

API そして 郵便 アーカイブも良いリソースです。たくさんあるようです 機関 参加する。

他のヒント

私はAggregateUnmarshallerから期待される結果を得ることができなかったときに私がやったように、この上でつまずくものについては...ここでの例です。

//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();
  }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top