/// <summary>
        ///     Returns list of all transactions in OFX document
        /// </summary>
        /// <param name="ofxDocument"></param>
        /// <param name="doc">OFX document</param>
        /// <returns>List of transactions found in OFX document</returns>
        private static void ImportTransations(OfxDocument ofxDocument, XmlDocument doc)
        {
            var xpath = GetXPath(ofxDocument.AccType, OfxSection.TRANSACTIONS);

            ofxDocument.StatementStart = doc.GetValue(xpath + "//DTSTART").ToDate();
            ofxDocument.StatementEnd   = doc.GetValue(xpath + "//DTEND").ToDate();

            var transactionNodes = doc.SelectNodes(xpath + "//STMTTRN");

            ofxDocument.Transactions = new List <OfxTransaction>();

            foreach (XmlNode node in transactionNodes)
            {
                ofxDocument.Transactions.Add(new OfxTransaction(node, ofxDocument.Currency));
            }
        }
        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);
        }