将源 xml 转换为另一个 xml 的方法
有一个 xml 源文档。现在我想将其转换为另一个内容相同但元素顺序不同的 xml 文档。我的想法是使用xslt,我认为这种方式也很好。
但是,我想知道还有其他方法吗?
谢谢
There's a source xml document. Now i want to transform it to another xml document with same content but different elements order. The thinking up to my mind is using xslt and i think this way is fine too.
However, i wanna to know are there some other ways to do so ?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
xslt 很好,但您也可以从脚本语言调用一些 XML 库,甚至用 C 或 C++ 编写程序......
这确实取决于性能考虑......(如果您每天必须处理数百 GB 大小的 XML 文档,或者一次只能处理几十兆字节的文档)。
xslt is good, but you could also call some XML library from a scripting language, or even write your program in C or C++ ....
It really depends of performance considerations.... (If you have to process hundreds of gigabyte sized XML documents daily, or only a few dozen of megabytes documents once).
您可以使用 Perl、Java、PHP、Ruby、Python 等编程语言来解析 XML,然后以所需的形式输出新的 XML。
但是,正如您所说,XSLT 是最好的方法。
You could use a programming language like Perl, Java, PHP, Ruby, Python, etc to parse the XML, then output the new one in the desired form.
But, as you said, XSLT is the best approach.
作为 XSLT 的替代方案并使用您最喜欢的编程语言,有一个命令行工具
xmlstarlet
,它可以使用比 xslt 简单得多的语法进行大量 xml 处理。请参阅此处了解概述http://xmlstar.sourceforge.net/overview.php
以及此处了解一个很好的教程:
http://www.ibm.com/developerworks/library/x-starlet/index.html
As an alternative to XSLT and using your favorite programming language, there is a command line tool
xmlstarlet
which can do a lot of xml processing with much simpler syntax than xslt. See here for an overviewhttp://xmlstar.sourceforge.net/overview.php
and here for a nice tutorial:
http://www.ibm.com/developerworks/library/x-starlet/index.html
还要考虑 XQuery。我通常的经验法则是,对于简单任务,XQuery 比 XSLT 更好,而对于复杂任务,XSLT 更好。您还没有向我们展示您的数据,但 XQuery 中的解决方案可能很简单
Also consider XQuery. My usual rule-of-thumb is that XQuery is better than XSLT for simple tasks, whereas XSLT is better for complex tasks. You haven't shown us your data, but the solution in XQuery might be as simple as