OFX File parser in C#

Bikal Lem picture Bikal Lem · Jul 28, 2010 · Viewed 7.9k times · Source

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.

Answer

Jo-Pierre picture Jo-Pierre · Apr 3, 2012

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) 
        { .... }

    }
}