最适合解析的文件格式是什么?
场景:我正在开发一个 Rails 应用程序,它将以上传的基于文本的文件的形式进行数据输入。我需要在导入数据之前解析这些文件。我可以选择上传到应用程序的文件类型;上传者使用的软件(Microsoft Access)有几个关于文件类型的导出选项。
虽然它可能微不足道,但我想知道是否有一种特定的文件类型可以最有效地解析。我相信这个问题可以被视为与语言无关。
(虽然 XML 通常被解析,但对于本项目而言,它不是可行的文件类型。)
Scenario: I'm working on a rails app that will take data entry in the form of uploaded text-based files. I need to parse these files before importing the data. I can choose the file type uploaded to the app; the software (Microsoft Access) used by those uploading has several export options regarding file type.
While it may be insignificant, I was wondering if there is a specific file type that is most efficiently parsed. This question can be viewed as language-independent, I believe.
(While XML is commonly parsed, it is not a feasible file type for sake of this project.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果是Access导出的东西,最简单的是CSV;特别是因为 Ruby 在标准库中包含一个 CSV 解析器。您必须做一些工作来确定 CSV 的方言(它使用什么作为分隔符,它如何处理引号);我不知道 ruby 解析器对于这些问题的鲁棒性如何,但您还应该对 Microsoft Access 进行一些控制。
If it is something exported by Access, the easiest would be CSV; particularly since Ruby contains a CSV parser in the standard library. You will have to do some work determining the dialect of CSV (what it uses for delimiter, how it handles quotes); I don't know how robust the ruby parser is with those issues, but you also should have some control from Microsoft Access.
您可能想查看 JSON。它是一种轻量级格式,与 XML 相比,它的解析非常简单、干净,不需要后端使用庞大的库。
它可以表示字符串、数字、关联数组(对象)以及此类列表等类型
You might want to take a look at JSON. It's a lightweight format, and in contrast to XML it's really easy and clean to parse without requiring a huge library on the backend.
It can represent types like strings, numbers, assosiative arrays (objects), and lists of such
对于不包含n的数据,我建议使用n-SV(其中n是某个字符)。这将使文件的词法分析成为
分割
的问题。如果你有更灵活的数据,我建议 JSON。
I would suggest n-SV (where n is some character) for data that does not include n. That will make lexing the files a matter of a
split
.If you have more flexible data, I would suggest JSON.
如果您必须使用自己的解析器,我建议您使用 CSV 或某种形式的分隔符分隔格式。
如果您能够使用其他库,那么还有很多选择。 JSON 看起来相当迷人。
If you've HAVE to roll your own parser, I would suggest CSV or some form of a delimiter separated format.
If you are able to use other libraries, there are plenty of options. JSON looks quite fascinating.