如何从XML元素生成XSD [英] How to generate XSD from elements of XML

查看:137
本文介绍了如何从XML元素生成XSD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有XML输入

<field>
  <name>id</name>
  <dataType>string</dataType>
  <maxlength>42</maxlength>
  <required>false</required>
</field>

我正在寻找一个库或工具,它将获取XML实例文档并输出相应的XSD schema。

I am looking for a library or a tool which will take an XML instance document and output a corresponding XSD schema.

我正在寻找一些java库,我可以用它为上面的XML结构生成一个XSD

I am looking for some java library with which I can generate a XSD for the above XML structure

推荐答案

如果您想要的只是一个XSD,以便您提供的XML符合它,那么您自己制作它而不是使用工具会更好。

If all you want is an XSD so that the XML you gave conforms to it, you'd be much better off by crafting it yourself rather than using a tool.

没有人比你更了解架构的特殊性,例如哪些有效值(例如,< maxlength> 需要的元素是 true false <需> ?)。

No one knows better than you the particularities of the schema, such as which valid values are there (for instance, is the <maxlength> element required? are true and false the only valid values for <required>?).

如果你真的想使用一个工具(如果你没有设计XML并且真的无法获得真正的XSD,我只会建议使用它 - 或者如果您设计了它,请仔细检查生成的XSD),您可以尝试 Trang 。它可以从许多示例XML中推断出XSD Schema。

If you really want to use a tool (I'd only advice using it if you haven't designed the XML and really can't get the real XSD - or if you designed it, double check the generated XSD), you could try Trang. It can infer an XSD Schema from a number of example XML's.

如果XML样本不够具有代表性,您必须考虑到工具可以推断出XSD可能不完整或不准确的XSD。

You'll have to take into account that the XSD a tool can infer you might be incomplete or inaccurate if XML samples aren't representative enough.

java -jar trang.jar sampleXML.xml inferredXSD.xsd

你可以找到 Trang的使用示例

这篇关于如何从XML元素生成XSD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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