简体   繁体   English

将内部数据元素映射到外部供应商的XML模式

[英]Mapping internal data elements to external vendors' XML schema

I'm considering Altova MapForce (or something similar) to produce either XSLT and/or a Java or C# class to do the translation. 我正在考虑使用Altova MapForce(或类似的东西)生成XSLT和/或Java或C#类来进行翻译。 Today, we pull data right out of the database and manually build an XML string that we post to a webservice. 今天,我们将数据从数据库中提取出来并手动构建我们发布到Web服务的XML字符串。

Should it be db -> (internal)XML -> XSLT -> (External)XML? 应该是db - >(内部)XML - > XSLT - >(外部)XML吗? What do you folks do out there in the wide world? 在广阔的世界里,你们有什么人做的?

I would use one of the out-of-the-box XML serialization classes to do your internal XML generation, and then use XSLT to transform to the external XML. 我将使用一个开箱即用的XML序列化类来进行内部XML生成,然后使用XSLT转换为外部XML。 You might generate a schema as well to enforce that the translation code (whatever will drive your XSLT translation) continues to get the XML it is expecting for translation in case of changes to the object breaks things. 您也可以生成一个模式,以强制执行转换代码(无论什么将驱动您的XSLT转换)继续获取它所期望的XML,以便在对象中断更改的情况下进行转换。

There are a number of XSLT editors on the market that will help you do the mappings, but I prefer to just use a regular XML editor. 市场上有许多XSLT编辑器可以帮助您进行映射,但我更喜欢使用常规的XML编辑器。

ya, I think you're heading down the right path with MapForce. 是的,我认为你正在使用MapForce走正确的道路。 If you don't want to write code to preform the actual transformation, MapForce can do that for you also. 如果您不想编写代码来执行实际转换,MapForce也可以为您执行此操作。 THis may be better long term b/c it's less code to maintain. 这可能是更好的长期b / c维护更少的代码。

Steer clear of more expensive options (eg BizTalk) unless you really need to B2B integration and orchestration. 除非您确实需要B2B集成和编排,否则请避开更昂贵的选项(例如BizTalk)。

What database are you using? 你用的是什么数据库? Oracle has some nice XML mapping tools. Oracle有一些很好的XML映射工具。 There are some Java binding tools (one is http://java.sun.com/developer/technicalArticles/WebServices/jaxb ). 有一些Java绑定工具(一个是http://java.sun.com/developer/technicalArticles/WebServices/jaxb )。 However, if you have the luxory consider using Ruby which has nice built-in "to_xml" methods. 但是,如果你有luxory考虑使用Ruby,它有很好的内置“to_xml”方法。

Tip #1: Avoid all use of XSLT. 提示#1:避免全部使用XSLT。

The tool support sucks. 工具支持太糟糕了。 The resulting solution will be unmaintainable. 由此产生的解决方案将无法维护。

Tip #2: Eliminate all unnecessary steps. 提示#2:消除所有不必要的步骤。

Just translate your resultset (assuming you're using JDBC or equiv) to the outbound XML. 只需将结果集(假设您使用JDBC或者等效)转换为出站XML。

Tip #3: Assume all use of a schema-based tool to be incorrect and plan accordingly. 提示#3:假设所有使用基于模式的工具都不正确并相应地进行规划。

In other words, just fake it. 换句话说,就是伪造它。 If you have to squirt out some mutant SOAP (redundant, I know) payload just mock up a working SOAP message and then turn it into a template. 如果你必须喷出一些突变SOAP(冗余,我知道)有效负载,只需模拟一个工作的SOAP消息,然后将其转换为模板。 Velocity doesn't suck. 速度不吸吮。

That said, the best/correct answer, is to use an "XML Writer" style solution. 也就是说,最好/正确的答案是使用“XML Writer”风格的解决方案。 There's a few. 有几个。

The best is the one I wrote, LOX (Lightweight Objects for XML) . 最好的是我写的那个, LOX(XML的轻量级对象)

The public API uses a Builder design pattern. 公共API使用Builder设计模式。 Due to some magic under the hood, it's impossible to create malformed XML. 由于引擎盖下的一些魔力,创建格式错误的XML是不可能的。

Please note: If XML is the answer, you've asked the wrong question. 请注意:如果XML是答案,那你就提出了错误的问题。 Sometimes, we're forced against our will to use it in some way. 有时,我们被迫违背我们的意愿以某种方式使用它。 When that happens, it's crucial to use tools which minimize developer effort and improve code maintainability. 当发生这种情况时,使用最小化开发人员工作并提高代码可维护性的工具至关重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM