Rick Strahl's Web Log

Wind, waves, code and everything in between...
ASP.NET • C# • HTML5 • JavaScript • AngularJs
Contact   •   Articles   •   Products   •   Support   •   Search
Ad-free experience sponsored by:
ASPOSE - the market leader of .NET and Java APIs for file formats – natively work with DOCX, XLSX, PPT, PDF, images and more

OFX Data parsing in .NET


:P
On this page:

I’m working on a project that needs to import a score of financial information using the OFX protocol which are used by Quicken and Money. When I started out on this I was glad to see that these protoocols have been updated to include schema support, so I was hoping that importing data into objects was going to be relative painless.

 

Unfortunately this is turning out to be not so – I haven’t had any luck getting OFX -> .NET objects to work. After some initial problems getting XSD.EXE to run against the OFX schemas I did get the classes generated, however in the end it turns out that the generated classes do not work correctly with the data that actually get returned. Part of the problem apparently is in the schema itself and how it represents the second level group header items. When I run the deserialization code against downloaded data the deserialization does not fail, but unfortunately it also fails to import the data correctly.

 

My Schema and XSD skills are fast fading and were never that strong actually – I haven’t worked in angle brackets in a while now <s>. But this demonstrates one of my big frustration with where XML has ended up, in that schemas in the handful of situations where I needed to use them in .NET with rather complex services rarely import directly without major tweaking.

 

I checked with Christian Wyer who’s been my goto guy on a few XML related issues in the past and his thoughts were that the schema had some qualifying errors and he deftly pinpointed a problem with the schema setting an unqualified elementFormDefault which caused the XSD.EXE to not import the data correctly. Taking his clue I went ahead and added explicit elementFormDefault=”qualified” to the schemas and sure enough that made the import work.

 

However, the class structure is pure hell… the classes have untyped array element types that one has to iterate through to figure out what type of element you’re dealing with which makes traversing this document not a whole lot easier than using raw XML. In fact it’s probably more difficult because there’s no way to get directly at any given lower level element via . syntax. At least with XML you can use XPath to jump into lower level nodes.

 

My buddy Peter Bromberg also kindly pointed me at XSDObjGen, which looks like a great tool that provides XSD like functionality for class generation from schema but is much more sophisticated in parsing the schema and inferring .NET style types. It can manage things like arrays/collections and enums and conditional lists much nicer. For example, it properly figured out the generic arrays in OFX and was able to create typed lists instead which is much easier to navigate. When I ran it against the schemas OFX schemas it created much cleaner looking classes that would be relatively easy to use from code. Unfortunately the generated class  also failed to work with the XML Serializer. Trying to instantiate the XmlSerializer with the generated type fails immediately with a type mismatch (Can’t convert DateTime to string).

 

It seems silly that the schemas for this stuff are so horrible. Heck the schemas don’t even provide strong type information for numeric and date data, so even with these mapped classes values still need to be converted. Well, actually it’s no surprise. This stuff originated from Inuit, which has a history of mismanaged APIs. <s>

 

There appears to be a new OFX version coming up and it looks like the schemas for that version provide a more .NET friendly schema interface, but unfortunately that version is rather incompatible with the 1.x version that most financial providers seem to be using (it looks like 2.x is compatible with 1.x at least).

 

So I’m curious – has anybody done this sort of OFX parsing in .NET? Searching around I haven’t seen anything. There’s a component from n/software that I’ve looked at but there are, uh… some problems with that as well. They’re looking into the issues, but it’s not terribly confidence inspiring that the first thing I tried breaks their component <s>… (leave it to me, to do that though).

 

If anybody’s gone down this path of OFX parsing I’d be interested in hearing from you before I head off and do this the brute force way <s>…  

Posted in XML  

The Voices of Reason


 

Aaron
February 01, 2007

# re: OFX Data parsing in .NET

I ran into this generating Classes for MISMO serialization, which involved converting dtd to schema then to a class I used XSDObjGen, And we had trouble with dates and time the MISMO spec and .NET didn't agree how they should be represented. During my research phase I was using XMLSPY to create the classes and while they worked they were a little fatter then I liked. So you might want to check what the latest version of XMLSPY can generate for you.

Aaron
February 01, 2007

# re: OFX Data parsing in .NET

Sorry I used Buisnessware Architects(http://www.bware.biz/) CodeXS. None of the microsoft stuff worked.

Rydal Williams
February 01, 2007

# re: OFX Data parsing in .NET

I simply wrote a custom parser that will parse qif/ofx/qfx files.

jason
February 16, 2007

# re: OFX Data parsing in .NET

I too am trying to do this. I want to write a C# basic application for inputing, and graphically displaying financial data. Part of this would be to download the data from the OFX servers. I have the server locations for lots of servers, and the spec, I was just hoping someone already wrote a parser. I am completely against paying money for it, so I rather just write my own if I have to. Any help would be appreciated.

jason
February 16, 2007

# re: OFX Data parsing in .NET

My website is at the following http://www.codelandia.com
I also have a forum setup to contact me.

George
February 26, 2007

# re: OFX Data parsing in .NET

Have you gotten anywhere with this project?

I tried the /n software component as well and found it to be simply awful. It could only download statements from half the banks I tried with correct OFX provider information, and could not get it to read a .ofx file correctly. I can't believe they're charging $599 for that thing.

Rick Strahl
February 26, 2007

# re: OFX Data parsing in .NET

Hi Geroge, I had sort of the same experience with n/software and the investment parsing I'm doing. I decided to just break down and parse the data on my own and I'm about half way through the investment parsing stuff. It's not too bad, but I am seriously worried about implementation differences between the FIs. I'll have to deal with that once we have more data to actually test with - for now I'm working off a couple of accounts with a few of the big brokerages.

I suspect it'll be the same with the banking data... apparently this will be an ongoing situation fixing as issues come up - no way that I can see to completely make this generic based on the differences.

# DotNetSlackers: OFX Data parsing in .NET


Rydal
July 26, 2007

# re: OFX Data parsing in .NET

Parsing it yourself is the best way to go and be prepared for changes on a frequent basis as you try to access more FI's.

Kyler
February 28, 2008

# re: OFX Data parsing in .NET

I'm starting to look into simple transactions download from credit card and bank companies. I'm not averse to writing my own parser. Any advice on which version I should write to? The latest (as of now) is 2.1.1. Are most financial institutions now implementing 2.x? American Express is of particular interest.

Ed Aymami
March 31, 2008

# re: OFX Data parsing in .NET

It is a year later And I have just run across this log googling to find tools to use OFX to download transactions into my accounting package aimed at small businesses. I can confirm that the /n software component referred to here STILL does not work very well. Their tech support is MOST unhelpful or supportive.

Does anyone know of ANY component out there that will work in visual studio?

ED

Jeff
December 04, 2009

# re: OFX Data parsing in .NET

does anyone have any code that they use to parse OFX's files?

West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2020