将 XML 转换为 X12 并将 X12 转换为 XML 的最佳方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/449312/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Best way to convert XML to X12 and X12 to XML
提问by jdigital
Looking for a tool/library to convert XML to X12 (270 - medical eligibility request) and then to convert the X12 response (271 - eligibility response) back to XML. This will be embedded in a server application (will consider any target language). I've toyed with idea of writing my own X12 parser and generator but this project will most likely expand to other X12 transactions and I'd like to find a solution that will be extensible.
寻找一个工具/库将 XML 转换为 X12(270 - 医疗资格请求),然后将 X12 响应(271 - 资格响应)转换回 XML。这将嵌入在服务器应用程序中(将考虑任何目标语言)。我曾想过编写自己的 X12 解析器和生成器,但这个项目很可能会扩展到其他 X12 事务,我想找到一个可扩展的解决方案。
采纳答案by jdigital
I ended up creating my own XML <-> x12 transformation tool. There were some commercial offerings that I came across (one of which, from EtaSoft, is worth checking out for their fine documentation) but ultimately the advantage of a homegrown solution was too great.
我最终创建了自己的 XML <-> x12 转换工具。我遇到了一些商业产品(其中一个来自EtaSoft,值得查看他们的精美文档),但最终,本土解决方案的优势太大了。
I did use the configuration files from X12::Parseras the basis for an X12 parser, essentially turning the config file into code and eliminating the overhead and error handling for managing configuration files that should in theory almost never change.
我确实使用了来自X12::Parser的配置文件作为 X12 解析器的基础,基本上将配置文件转换为代码,并消除了管理配置文件的开销和错误处理,理论上应该几乎不会改变。
回答by JonK
I came across this: OopFactory X12 Parser - https://x12parser.codeplex.com/releases/view/106524
我遇到了这个:OopFactory X12 Parser - https://x12parser.codeplex.com/releases/view/106524
Incredible. Source code was well structured, everything built on first open, even had unit tests.
极好的。源代码结构良好,一切都建立在第一次开放的基础上,甚至有单元测试。
Pulled into my project, it converted all the files I tried.
拉入我的项目,它转换了我尝试过的所有文件。
It includes a command line exe which worked - but as a .Net guy the library was really impressive.
它包括一个可以工作的命令行 exe - 但作为一个 .Net 人,这个库确实令人印象深刻。
-Update-
-更新-
The short short version comes down to something like this:
简短的简短版本归结为这样的:
var fstream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
var parser = new X12Parser();
var interchange = parser.ParseMultiple(fstream).First();
var x12Xml = interchange.Serialize();
回答by BBlake
One product I can speak to that you should avoid at all costs is EcMap. Having had about a year of experience with it now in my own employment in an EDI department, I can say I have seldom seen an application with a more poorly designed interface (except perhaps Lotus Notes), more confusing user documentation, and an absolutely ridiculous licensing scheme. It's essentially licensed per CPU (by CPU they mean core, so you're really hosed if you've got a new quad-core CPU) and it's more than 10K per license by the last quote I heard.
我可以说的一种产品是 EcMap,你应该不惜一切代价避免。我现在在 EDI 部门有大约一年的使用经验,我可以说我很少见过界面设计更差的应用程序(可能除了 Lotus Notes)、更混乱的用户文档和绝对荒谬的许可计划。它基本上是按 CPU 授权的(CPU 的意思是核心,所以如果你有一个新的四核 CPU,你真的很受打击),而且根据我听到的最后一句话,每个许可证超过 10K。
回答by S.Lott
回答by Abe
Here is an example of using pyx12to write to an XML file
下面是使用pyx12写入 XML 文件的示例
import pyx12.x12n_document
fd_source = "/path/to/edi/file"
output_file = "result.xml"
with open(output_file, 'w') as fd_xml:
result = pyx12.x12n_document.x12n_document(param=param, src_file=fd_source,
fd_997=None, fd_html=None, fd_xmldoc=fd_xml, xslt_files=None)

