Xsd 到 rnc(或 rng)转换(unix 命令行) [英] Xsd to rnc (or rng) conversion (unix command line)

查看:40
本文介绍了Xsd 到 rnc(或 rng)转换(unix 命令行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简短的搜索表明,所有从 xsd(XML Schema)转换为 rng(RelaxNG)或 rnc(compactRelaxNG)的可用(uUnix 命令行)工具都存在某种问题.

A brief search shows that all available (uUnix command line) tools that convert from xsd (XML Schema) to rng (RelaxNG) or rnc (compact RelaxNG) have problems of some sort.

首先,如果我使用 rngconv:

First, if I use rngconv:

$ wget https://msv.dev.java.net/files/documents/61/31333/rngconv.20060319.zip
$ unzip rngconv.20060319.zip
$ cd rngconv-20060319/
$ java -jar rngconv.jar my.xsd  > my.rng

它没有办法对元素进行反规范化,因此所有元素最终都成为替代的起始元素(它似乎也有点问题).

It does not have a way to de-normalize elements so all end up being alternative start elements (it also seems to be a bit buggy).

Trang 是一种替代方法,但它仅在输出上不支持输入上的 xsd 文件(为什么?).但是,它支持 DTD.首先想到的是转换为 DTD,但也很难找到可靠的 xsd2dtd.下面一张:

Trang is an alternative, but it doesn't support xsd files on the input only on the output (why?). It supports DTD, however. Converting to DTD first comes to mind, but a solid xsd2dtd is hard to find as well. The one below:

 $ xsltproc http://crism.maden.org/consulting/pub/xsl/xsd2dtd.xsl in.xsd > out.dtd

好像有问题.

这一切都非常令人惊讶.这么多年的 XML (ab) 使用,有没有像样的命令行工具来处理这些琐碎的基本任务?人们是否只使用编辑器?这些有用吗?我更喜欢命令行,尤其是因为我想自动化这些任务.

All this is very surprising. For all these years of XML (ab)use, there no decent command line tools for these trivial basic tasks? Are people using only editors? Do those work? I much prefer command line, especially because I'd like to automate these tasks.

对此有何启发性评论?

推荐答案

确实,trang 在输入端不接受 xsd.然而,Trang 可以采用一组应符合规范的 xml 文件,并生成一个它们都有效的 rnc 或 rng 模式.

True, trang does not accept xsd on the input side. Trang can however take a set of xml files which should meet the spec and generate a rnc or rng schema which they would all be valid against.

缺点:

  • 它需要许多兼容的 xml 文件(我认为越多越好)
  • 结果架构可能仍需进行一些调整.

示例:

如果我的兼容 xml 文件存储在 1.xml 2.xml 3.xml 4.xml 5.xml

If my compliant xml files are stashed in 1.xml 2.xml 3.xml 4.xml 5.xml

以下命令将告诉 trang 输出对所有这些都有效的 rnc 模式:

the following command would tell trang to output a rnc schema that would be valid for all of them:

java -jar trang.jar -I xml -O rnc 1.xml 2.xml 3.xml 4.xml 5.xml foo.rnc

结论

如果您有一个很好的 xml 文件测试集满足您的架构(或者您可以轻松创建它们),这可能是最好的选择.

If you have a nice test set of xml files which meet your schema (or you can easily create them) this may be the best option available.

祝你好运.

这篇关于Xsd 到 rnc(或 rng)转换(unix 命令行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆