Xsd to rnc (or rng) conversion (unix command line)

后端 未结 5 484
忘了有多久
忘了有多久 2020-12-30 08:00

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.

相关标签:
5条回答
  • 2020-12-30 08:35

    Another possibility might be http://www.brics.dk/schematools/, but I didn't try it yet.

    0 讨论(0)
  • 2020-12-30 08:37

    Converting XSD is a very hard task; the XSD specification is a bit of a nightmare and extremely complex. From some quick research, it seems that it is easy to go from RelaxNG to XSD, but that the reverse may not be true or even possible (which explains your question about Trang).

    I don't understand your question about editors - if you are asking if most people end up converting between XSD and RNG by hand, then yes, I expect so.

    The best advice may be to avoid XSD if possible, or at least use RNG as the definitive document and generate the XSD from that. You might also want to take a look at schematron.

    0 讨论(0)
  • 2020-12-30 08:40

    There is an online converter (XSD -> RNG) added to the list at http://relaxng.org/#conversion. I have tried to convert maven-v4_0_0.xsd for validation of pom.xml files in emacs, without any luck though. The site also contains the XSL stylesheet that you could use with xsltproc, can't vouch for the quality of the outcome...

    0 讨论(0)
  • 2020-12-30 08:51

    Again, regarding editors: I see that there's no way to do this with Oxygen which seems to be a popular tool.

    0 讨论(0)
  • 2020-12-30 08:53

    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.

    Downsides:

    • It requires many compliant xml files (I'd imagine the more the better)
    • Resulting schema could probably still use some tweaking.

    Sample Case:

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

    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
    

    Conclusion

    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.

    I wish you the best of luck.

    0 讨论(0)
提交回复
热议问题