转换 XML 格式

发布于 2024-08-20 05:26:42 字数 438 浏览 2 评论 0原文

我们遇到一个问题,我们有一个 XML 提要离开我们的系统,而客户需要能够将此提要导入到他们的系统中,但他们要求 XML 文件采用不同的格式。由于多种原因,我们中的任何一个人都不可能改变我们的格式。当时我在想,我们应该建立某种桥梁,导入我们的格式并以他们的格式导出。显然,当我们知道每个位置的格式时,这非常简单。不过,我想做的是构建一些更通用的东西,而不是针对该客户的特定东西,这样这个桥就可以被很多需要的人使用。为了实现这一目标我应该注意什么?我可以想到很多方法,例如包含占位符元素的模板文档和某种形式的映射数据(XML 或数据库),但在我看来应该有一个更优雅的解决方案 - 也许像 PHP XSL 扩展。我们主要使用 PHP 工作,因此基于 PHP 的解决方案将是理想的选择,但我很乐意考虑任何可以在 Linux 机器上运行的解决方案。

We have an issue where we have an XML feed leaving our system and a client needs to be able to import this feed into their system but they require the XML file to be in a different format. For a number of reasons its not possible for either of us to alter our format. I was thinking then that it would make sense for us to build some kind of bridge, that imports our format and exports it in theirs. Obviously this is pretty simple when we know the formats in each position. What I would like to do though is build something more generic and less specific to that client so this bridge could be used by a number of people should they need it. What should I be looking at to achieve this? There are a number of methods I can think of such as template documents containing placeholder elements and some form of mapping data (in XML or in a DB) but it seems to me there should be a more elegant solution - maybe like the PHP XSL extension. We work predominantly in PHP so a PHP-based solution would be ideal but i'd be happy to consider anything that would work on a Linux box.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

辞别 2024-08-27 05:26:42

就您问题的“转换”部分而言,是的,XSLT 将是一种合理的方法。

但就问题的“如果需要的话可以被许多人使用”部分而言,不要尝试基于单个示例构建通用系统。当您要为三四个客户端转换 XML 时,就该找出它们的共同点了。

As far as the "transforming" part of your question is concerned, yes, XSLT would be a reasonable approach.

But as far as the "could be used by a number of people should they need it" part of the question, don't try to build a generic system based on a single example. When you have three or four clients for which you're transforming your XML, then would be the time to find out what they all have in common.

彻夜缠绵 2024-08-27 05:26:42

是的,XSLT 在将一种 XML 格式转换为另一种 XML 格式方面相当有效,因此是“T”。我过去曾使用过它并取得了巨大成功。

Yes, XSLT is fairly effective at transforming one XML format to another, hence the "T". I've used it in the past with great success.

淡淡绿茶香 2024-08-27 05:26:42

事实上,XSLT 是正确的选择。

这里有一些资源:http://www.w3schools.com/xsl/default.asp

PHP 的 XSL 扩展确实是使其运行的一种简单方法。

Indeed, XSLT is the way to go.

Some resources here: http://www.w3schools.com/xsl/default.asp

And the XSL extension for PHP is indeed an easy way to make it run.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文