public OfxTransaction(XmlNode node, string currency) { TransType = GetTransactionType(node.GetValue(".//TRNTYPE")); Date = node.GetValue(".//DTPOSTED").ToDate(); TransactionInitializationDate = node.GetValue(".//DTUSER").ToDate(); FundAvaliabilityDate = node.GetValue(".//DTAVAIL").ToDate(); try { Amount = Convert.ToDecimal(node.GetValue(".//TRNAMT"), CultureInfo.InvariantCulture); } catch (Exception ex) { throw new OfxParseException("Transaction Amount unknown", ex); } try { TransactionId = node.GetValue(".//FITID"); } catch (Exception ex) { throw new OfxParseException("Transaction ID unknown", ex); } IncorrectTransactionId = node.GetValue(".//CORRECTFITID"); //If Transaction Correction Action exists, populate var tempCorrectionAction = node.GetValue(".//CORRECTACTION"); TransactionCorrectionAction = !string.IsNullOrEmpty(tempCorrectionAction) ? GetTransactionCorrectionType(tempCorrectionAction) : OfxTransactionCorrectionType.NA; ServerTransactionId = node.GetValue(".//SRVRTID"); CheckNum = node.GetValue(".//CHECKNUM"); ReferenceNumber = node.GetValue(".//REFNUM"); Sic = node.GetValue(".//SIC"); PayeeId = node.GetValue(".//PAYEEID"); Name = node.GetValue(".//NAME"); Memo = node.GetValue(".//MEMO"); //If differenct currency to CURDEF, populate currency if (NodeExists(node, ".//CURRENCY")) { Currency = node.GetValue(".//CURRENCY"); } else if (NodeExists(node, ".//ORIGCURRENCY")) { Currency = node.GetValue(".//ORIGCURRENCY"); } //If currency not different, set to CURDEF else { Currency = currency; } //If senders bank/credit card details avaliable, add if (NodeExists(node, ".//BANKACCTTO")) { TransactionSenderAccount = OfxAccount.FromXmlNode(node.SelectSingleNode(".//BANKACCTTO"), OfxAccountType.BANK); } else if (NodeExists(node, ".//CCACCTTO")) { TransactionSenderAccount = OfxAccount.FromXmlNode(node.SelectSingleNode(".//CCACCTTO"), OfxAccountType.CC); } }
private static OfxDocument Parse(string content) { //If OFX file in SGML format, convert to XML if (!IsXmlVersion(content)) { content = SgmlToXml(content); } var ofx = new OfxDocument { AccType = GetAccountType(content) }; //Load into xml document var doc = new XmlDocument(); doc.Load(new StringReader(content)); var currencyNode = doc.SelectSingleNode(GetXPath(ofx.AccType, OfxSection.CURRENCY)); if (currencyNode != null) { ofx.Currency = currencyNode.FirstChild.Value; } else { throw new OfxParseException("Currency not found"); } //Get sign on node from OFX file var signOnNode = doc.SelectSingleNode(Resources.SignOn); //If exists, populate signon obj, else throw parse error if (signOnNode != null) { ofx.SignOn = new OfxSignOn(signOnNode); } else { throw new OfxParseException("Sign On information not found"); } //Get Account information for ofx doc var accountNode = doc.SelectSingleNode(GetXPath(ofx.AccType, OfxSection.ACCOUNTINFO)); //If account info present, populate account object if (accountNode != null) { ofx.Account = OfxAccount.FromXmlNode(accountNode, ofx.AccType); } else { throw new OfxParseException("Account information not found"); } //Get list of transactions ImportTransations(ofx, doc); //Get balance info from ofx doc var ledgerNode = doc.SelectSingleNode(GetXPath(ofx.AccType, OfxSection.BALANCE) + "/LEDGERBAL"); var avaliableNode = doc.SelectSingleNode(GetXPath(ofx.AccType, OfxSection.BALANCE) + "/AVAILBAL"); //If balance info present, populate balance object // ***** OFX files from my bank don't have the 'avaliableNode' node, so i manage a 'null' situation if (ledgerNode != null) // && avaliableNode != null { ofx.Balance = new OfxBalance(ledgerNode, avaliableNode); } else { throw new OfxParseException("Balance information not found"); } return(ofx); }