c# - C# 中的 OFX​​ 文件解析器

标签 c# ofx

我正在寻找 C# 中的 OFX​​ 文件解析器库。我在网上搜索过,但似乎没有。有谁知道任何优质的 C# OFX 文件解析器。我需要处理一些 OFX 格式的银行对帐单文件。

更新 我设法找到了一个用于解析 OFX 解析器的 C# 库。

这是链接ofx sharp .此代码库似乎是启动我的解决方案的最佳案例。

最佳答案

我尝试使用 ofx sharp 库,但意识到它不起作用,因为该文件不是有效的 XML ...它似乎可以解析但具有空值 ...

我在 OFXDocumentParser.cs 中进行了更改,首先将文件修复为有效的 XML,然后让解析器继续。不确定您是否遇到过同样的问题?

方法内部:

private string SGMLToXML(string file)

我先添加了几行以将文件转换为新文件,然后让 SqmlReader 在以下代码之后进行处理:

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 是我添加到 OFXSharp 库中的新类。它基本上扫描所有打开的标签并验证它也有一个结束标签。

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

    }
}

关于c# - C# 中的 OFX​​ 文件解析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3351200/

相关文章:

php - 如何在 PHP 中解析 OFX(版本 1.0.2)文件?

c# - SelectMany 匿名类型并跳过迭代

c# - 如何将 USB 设备按钮转换为模拟 C# 中的键盘按钮?

c# - 如何在多个描述字符之间拆分字符串?

c# - 具有租户特定角色的 ASP.NET Multi-Tenancy 应用程序

c# - 在 SQL 中更改隔离级别时的 SqlConnection 行为

csv - Python : How to convert . ofx 文件转换为 .csv

java - 用java解析Ofx文件