帮助将文件格式翻译或转换为其他文件格式的库
我需要将谱系文件与 OpenGen XML 文件格式相互转换。很简单,我可以编写 Java 代码来解析特定文件并输出 OpenGen 文件。如果有人在他们的项目中使用 Java,他们可以使用我们的库。如果有人在他们的项目中不使用 Java,他们可以移植我们的翻译代码或在外部运行我们的 Java 应用程序。
由于这必须是一个非常常见的需求,我希望有一种机制可以使这变得更容易。理想的解决方案是这样的,我可以创建一个包含规则/映射的文件,以在一种文件格式和我们的格式之间进行转换。然后分发该映射文件,以便其他任何人都可以使用可以使用该映射文件执行翻译的许多库之一。这样,翻译就变得更加容易,现在任何人都可以在他们选择的语言/平台内进行翻译。
我想在我们的例子中,映射文件会有点复杂,因为至少需要处理层次结构。我想事情变得更加复杂的是,某些谱系文件格式是二进制的......
这样的机制是否存在?最好的方法是什么?
I need to convert genealogy files to and from the OpenGen XML file format. Simple enough, I can write Java code to parse a particular file and output an OpenGen file. If someone uses Java in their project, they can use our library. If someone does not use Java in their project, they can either port our translating code or run our Java application externally.
Since this has to be a pretty common need, I'm hoping there's a mechanism out there to make this easier. The ideal solution is this, I can create a file which contains rules/mappings to translate between one file format and our format. This mapping file is then distributed so that anyone else can use one of many libraries that can perform the translation using this mapping file. This way, translating is much easier and now anyone can do translations within their language/platform of choice.
I guess in our case, the mapping file would be a little complex in that there are at least hierarchies to deal with. I guess further complicating things is that some genealogy file formats are binary...
Does such a mechanism exist? What's the best approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的源语言始终是 XML,则可以使用 XSLT 或 CDuce。
否则,您需要一个像样的解析和漂亮的打印框架,例如 Antlr,并准备好付出大量的努力。对于一些简单的情况,实现您自己的基于组合器的 Packrat 解析器会更容易。
If your source language is always XML, you could use XSLT or CDuce.
Otherwise you'd need a decent parsing and pretty-printing framework, like Antlr, and be prepared to commit a lot of effort. For some trivial cases it's easier to implement your own combinator-based Packrat parser.