Forum Discussion

Re: Need an OFX parser to import Bank Transactions to quick base

>Seems that OFX files are something similar to xml and readable with file reader.

OFX files are not XML. There is a header with attribute value pairs followed by something that looks like XML but isn't (it is SGML without the requirement of closing tags). You will probably have to parse the OFX file using regular expressions. If you isolate the text after the header you can attempt to parse the thing that looks like XML using code similar to this:

var doc = "";
doc += "<STMTTRN>";
doc += "  <TRNTYPE>CHECK ";
doc += "  <DTPOSTED>20150930 ";
doc += "  <TRNAMT>-15840.00 ";
doc += "  <FITID>2015093011584000 ";
doc += "  <CHECKNUM>850093 ";
doc += "  <MEMO>CHEQUE PAGO OUTRA AG NCIA ";
doc += "</STMTTRN>";

var TRNTYPE = doc.match(/<TRNTYPE>(.*?)</)[1].trim();
console.log("TRNTYPE=" + TRNTYPE); // outputs: TRNTYPE=CHECK

The key is to use a catapulting group with the non-greedy regexp: (.*?)
No RepliesBe the first to reply