Tutorial :OFX File parser in C#



Question:

I am looking for an OFX file parser library in C#. I have search the web but there seems to be none. Does anyone know of any good quality C# OFX file parser. I need to process some bank statements files which are in OFX format.

Update I have managed to find a C# library for parsing OFX parser.

Here is the link ofx sharp. This codebase seems to be the best case to startup my solution.


Solution:1

I tried to use the ofx sharp library, but realised it doesn't work is the file is not valid XML ... it seems to parse but has empty values ...

I made a change in the OFXDocumentParser.cs where I first fix the file to become valid XML and then let the parser continue. Not sure if you experienced the same issue?

Inside of the method:

private string SGMLToXML(string file)  

I added a few lines first to take file to newfile and then let the SqmlReader process that after the following code:

string newfile = ParseHeader(file);    newfile = SGMLToXMLFixer.Fix_SONRS(newfile);  newfile = SGMLToXMLFixer.Fix_STMTTRNRS(newfile);  newfile = SGMLToXMLFixer.Fix_CCSTMTTRNRS(newfile);      //reader.InputStream = new StringReader(ParseHeader(file));  reader.InputStream = new StringReader(newfile);  

SGMLToXMLFixer is new class I added into the OFXSharp library. It basically scans all the tags that open and verifies it has a closing tag too.

namespace OFXSharp  {      public static class SGMLToXMLFixer      {          public static string Fix_SONRS(string original)           { .... }            public static string Fix_STMTTRNRS(string original)           { .... }            public static string Fix_CCSTMTTRNRS(string original)           { .... }            private static string Fix_Transactions(string file, string transactionTag, int lastIdx, out int lastIdx_new)           { .... }            private static string Fix_Transactions_Recursive(string file_modified, int lastIdx, out int lastIdx_new)           { .... }        }  }  


Solution:2

Try http://www.codeproject.com/KB/aspnet/Ofx_to_DataSet.aspx. The code uses Framework 3.5 and transforms an ofx into a dataset, this may help with what you're trying to do.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »